Closed9
Node.jsのバージョン管理ツール「fnm」をWSL2 ubuntu 20.04 環境にインストールする
![warugaki](https://res.cloudinary.com/zenn/image/fetch/s--tUiT4xhr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/3dab0caae7.jpeg)
インストール
curl -fsSL https://fnm.vercel.app/install | bash
Shell Setup
.node-version
or .nvmrc
があるとNodeを自動インストール or 自動切換えできるように
以下の関数を.bashrc
に追加
__fnm_use_if_file_found() {
if [[ -f .node-version || -f .nvmrc ]]; then
fnm use
fi
}
__fnmcd() {
\cd "$@" || return $?
__fnm_use_if_file_found
}
alias cd=__fnmcd
__fnm_use_if_file_found
挙動確認
node14
と node16
フォルダを作り、
それぞれにnodeのバージョンを書いた .node-version または .nvmrc
ファイルを配置
この段階ではnodeは未インストール
cd node14
Can't find an installed Node version matching v14.x.x.
Do you want to install it? answer [y/n]: y
Installing Node v14.18.2 (x64)
Using Node v14.18.2
cd ../node16
Can't find an installed Node version matching v16.x.x.
Do you want to install it? answer [y/n]: y
Installing Node v16.13.1 (x64)
Using Node v16.13.1
このスクラップは2021/12/30にクローズされました