Closed9

Node.jsのバージョン管理ツール「fnm」をWSL2 ubuntu 20.04 環境にインストールする

warugakiwarugaki

https://github.com/Schniz/fnm

インストール

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

挙動確認

node14node16 フォルダを作り、
それぞれに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
Hidden comment
Hidden comment
Hidden comment
Hidden comment
Hidden comment
Hidden comment
Hidden comment
Hidden comment
このスクラップは2021/12/30にクローズされました