🦁

WSLのUbuntuにHomebrewとasdfを導入する

2023/11/03に公開

環境

  • WSL2
  • Ubuntu 22.04.3 LTS

Homebrewのインストール

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

(省略)
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/fagai/.bashrc
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Install Homebrew's dependencies if you have sudo access:
    sudo apt-get install build-essential
  For more information, see:
    https://docs.brew.sh/Homebrew-on-Linux
- We recommend that you install GCC:
    brew install gcc
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

PATHを通します。

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> ~/.bashrc

パスが通ってバージョンが確認できるかチェック

$ source ~/.bashrc
$ brew --version
Homebrew 4.1.18

以下のドキュメントを確認しつつ、アウトプットされてるコマンドをもとにインストール
https://docs.brew.sh/Homebrew-on-Linux

sudo apt-get update
sudo apt-get install build-essential

おすすめされているgccを入れておく。

brew install gcc

asdfの導入

$ brew install asdf

==> asdf
To use asdf, add the following line (or equivalent) to your shell profile
e.g. ~/.profile or ~/.zshrc:
  . /home/linuxbrew/.linuxbrew/opt/asdf/libexec/asdf.sh
e.g. ~/.config/fish/config.fish
  source /home/linuxbrew/.linuxbrew/opt/asdf/libexec/asdf.fish
Restart your terminal for the settings to take effect.

Bash completion has been installed to:
  /home/linuxbrew/.linuxbrew/etc/bash_completion.d
echo '. /home/linuxbrew/.linuxbrew/opt/asdf/libexec/asdf.sh' >> ~/.profile
source ~/.profile

nodejs用のプラグインを入れる

asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

情報を更新して、現状のLTSバージョンを解決する

asdf nodejs update-nodebuild
asdf nodejs resolve lts --latest-available

最新のバージョンを取得できるようにする

echo 'export ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY=latest_available' >> ~/.bashrc
$ asdf install nodejs lts
Trying to update node-build... ok
Downloading node-v20.9.0-linux-x64.tar.gz...
-> https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.gz
Installing node-v20.9.0-linux-x64...
Installed node-v20.9.0-linux-x64 to /home/fagai/.asdf/installs/nodejs/lts

バージョンが取得できるか確認。私の環境だとコンソールを立ち上げ直さないと取得できなかったです。

$ node -v
v20.9.0
$ which node
/home/fagai/.asdf/shims/node

Discussion