nvmコマンドラインから異なるバージョンのNodeをすばやくインストールして使用できます。
例:
$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
v16.9.1
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
v14.18.0
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v
v12.22.6
そのような単純な!
NVM は node.js のバージョンマネージャーであり、ユーザーごとにインストールされ、シェルごとに呼び出されるように設計されています。 POSIX 準拠のシェル (sh、dash、ksh、zsh、bash)、特に unix、macOS、および Windows WSL のプラットフォームで動作します。
nvm
nvmをインストールまたは更新するには、インストールスクリプトを実行する必要があります。これを行うには、スクリプトを手動でダウンロードして実行するか、次のcURLまたはWgetコマンドを使用します。
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
上記のコマンドのいずれかを実行すると、スクリプトがダウンロードされて実行されます。このスクリプトは、nvm リポジトリを に複製し、次のスニペットのソース行を正しいプロファイル ファイル (、、、、または) に追加しようとします。
~/.nvm
~/.bash_profile
~/.zshrc
~/.profile
~/.bashrc
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
環境変数が存在する場合は、そこにファイルが配置されます。
$XDG_CONFIG_HOME
nvm
上記のスクリプトの末尾 (...) に追加して、手動で使用する
まで使用を延期できます。
--no-use
nvm.sh --no-use
nvm
インストール・ソース、ディレクトリー、プロファイル、およびバージョンは、および変数を使用してカスタマイズできます。 例えば:。に末尾のスラッシュが含まれていないことを確認します。
NVM_SOURCE
NVM_DIR
PROFILE
NODE_VERSION
curl ... | NVM_DIR="path/to/nvm"
NVM_DIR
インストーラーは、または のいずれか使用可能な方をダウンロードできます。
git
curl
wget
nvm
Linuxでは、インストールスクリプトを実行した後、入力後にターミナルからフィードバックが得られない場合、または表示されない場合は、現在のターミナルを閉じて新しいターミナルを開き、もう一度確認してみてください。 または、コマンドラインでさまざまなシェルに対して次のコマンドを実行することもできます。
nvm: command not found
command -v nvm
バッシュ:
source ~/.bashrc
zsh:
source ~/.zshrc
ksh:
. ~/.profile
これらはコマンドを取得する必要があります。
nvm
OS X 10.9以降、Xcodeコマンドラインツールによってプリセットされているため、Gitがインストールされているかどうかを正しく検出できません。インストールスクリプトを実行する前に、Xcodeコマンドラインツールを手動でインストールする必要があります。(#1782を参照
/usr/bin/git)
インストールスクリプトを実行した後に取得する場合は、次のいずれかが原因である可能性があります。
nvm: command not found
macOS 10.15以降、デフォルトのシェルは nvmは更新を探しますが、デフォルトでは何もインストールされていません。で作成し、インストールスクリプトを再度実行します。
zsh
.zshrc
touch ~/.zshrc
以前のデフォルトシェルであるbashを使用する場合、システムにコマンドが設定されているファイルがない可能性があります。or を使用してそれらの 1 つを作成し、インストール スクリプトを再度実行します。次に、またはを実行してコマンドを取得します。
.bash_profile
.bashrc
touch ~/.bash_profile
touch ~/.bashrc
. ~/.bash_profile
. ~/.bashrc
nvm
以前に を使用したことがありますが、インストール済みです。これらの行を手動でに追加して実行する必要があります。
bash
zsh
~/.zshrc
. ~/.zshrc
ターミナルインスタンスを再起動するか、を実行する必要がある場合があります。ターミナルを再起動する/新しいタブ/ウィンドウを開くか、sourceコマンドを実行すると、コマンドと新しい構成がロードされます。
. ~/.nvm/nvm.sh
上記で問題が解決しない場合は、ターミナルインスタンスを再起動する必要があります。ターミナルで新しいタブ/ウィンドウを開いて再試行してみてください。
上記で問題が解決しない場合は、次のことを試してください。
bashを使用している場合は、あなた(または)が適切にソース化されていない可能性があります。これに追加して修正するか、以下の次の手順に従ってください。
.bash_profile
~/.profile
~/.bashrc
source ~/<your_profile_file>
正しいnvmディレクトリを見つけてnvmをロードするインストールセクションのスニペットを通常のプロファイル(、、または)に追加してみてください。
~/.bash_profile
~/.zshrc
~/.profile
~/.bashrc
この問題の詳細と可能な回避策については、こちらを参照してください。
手記M1チップを搭載したMacの場合、ノードはv16.0.0以降からarm64アーチダーウィンパッケージの提供を開始し、v14.17.0以降ソースからコンパイルする場合の実験的なarm64サポートを開始しました。を使用してノードをインストールする際に問題が発生した場合は、これらのバージョンのいずれか以降に更新することをお勧めします。
nvm
次のタスクを使用できます。
- name: Install nvm
ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
nvmがインストールされていることを確認するには、次のようにします。
command -v nvm
インストールが成功した場合に出力されます。実行可能なバイナリではなく、ソース化されたシェル関数であるため、動作しないことに注意してください。
nvm
which nvm
nvm
手記:Linuxでは、インストールスクリプトを実行した後、入力後にターミナルからフィードバックが得られない場合、または表示されない場合は、現在のターミナルを閉じて新しいターミナルを開き、もう一度確認してみてください。
nvm: command not found
command -v nvm
パッケージ化されたバイナリが利用できないシステムを実行している場合、つまりソースコードからnodejsまたはio.jsをインストールする場合は、システムにC ++コンパイラがあることを確認する必要があります。OS XではXcodeが動作し、Debian/UbuntuベースのGNU/Linuxではパッケージが動作します。
build-essential
libssl-dev
注:場合によってはWindowsもサポートします。WSL のバージョンに応じて、WSL (Windows Subsystem for Linux) を介して動作するはずです。また、GitBash (MSYS) または Cygwin でも動作するはずです。それ以外の場合、Windowsの場合、いくつかの代替手段が存在しますが、これらはサポートも開発もされていません。
nvm
注:Fishもサポートしていません(#303を参照)。代替案が存在しますが、これは私たちがサポートも開発もしていません。
nvm
手記:FreeBSD には公式のビルド済みバイナリがなく、ソースからのビルドにはパッチが必要な場合があるため、 FreeBSD にはまだいくつかの問題があります。発行チケットを参照してください。
手記:OS X では、Xcode がインストールされておらず、~4.3GB ファイルをダウンロードしたくない場合は、.あなたはちょうどその方法についてこのブログ投稿をチェックすることができます:
Command Line Tools
手記:OS Xでは、「システム」ノードがインストールされていて、モジュールをグローバルにインストールしたい場合は、次の点に注意してください。
nvm
sudo
npm -g
sudo npm install -g grunt
npm install -g grunt
~/.npmrc
prefix
nvm)
nvm
/usr/local/lib/node_modules/*
~/.nvm/versions/node/vX.X.X/lib/node_modules/*
自作のインストールはサポートされていません。問題が発生した場合 自作インストール 、それをお願いします、そして問題を報告する前に、以下の手順に従ってインストールしてください。
nvm
brew uninstall
手記:使用している場合は、zshプラグインとして簡単にインストールできます。zsh-nvm
をインストールし、実行してアップグレードします。
zsh
nvm
nvm upgrade
手記:v1.7より前のバージョンのGitは、httpsプロトコルを介してGitHubからソースをクローンする問題に直面する可能性があり、v1.6より前のgitの動作も異なり、v1.17.10より前のgitはタグを複製できないため、最低限必要なgitバージョンはv1.7.10です。ここで説明した問題に興味がある場合は、GitHubのHTTPSクローン作成エラーの記事を参照してください。
nvm
インストールしている場合(git v1.7.10+が必要):
git
cd ~/どこからでも
git clone https://github.com/nvm-sh/nvm.git .nvm
cd ~/.nvmで最新バージョンをチェックしてください
git checkout v0.39.3
nvm
. ./nvm.sh
次に、これらの行を、、またはファイルに追加して、ログイン時に自動的にソース化されるようにします。 (上記のファイルの複数に追加する必要があります)
~/.bashrc
~/.profile
~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
完全に手動インストールする場合は、次の行を実行して、最初にリポジトリを にクローンし、次にロードします。
nvm
$HOME/.nvm
nvm
export NVM_DIR="$HOME/.nvm" && (
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
次に、これらの行を、、またはファイルに追加して、ログイン時に自動的にソース化されるようにします。 (上記のファイルの複数に追加する必要があります)
~/.bashrc
~/.profile
~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
手動アップグレードの場合(git v1.7.10+が必要):
git
$NVM_DIR
(
cd "$NVM_DIR"
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
ノードの最新リリースをダウンロード、コンパイル、およびインストールするには、次のようにします。
nvm install node # "node" is an alias for the latest version
特定のバージョンのノードをインストールするには:
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
最初にインストールされたバージョンがデフォルトになります。新しいシェルは、ノードのデフォルトバージョン(例:)で開始されます。
nvm alias default
以下を使用して、使用可能なバージョンを一覧表示できます。
ls-remote
nvm ls-remote
そして、新しいシェルでは、インストールされているバージョンを使用してください。
nvm use node
または、単に実行することもできます。
nvm run node --version
または、目的のバージョンのノードを持つサブシェルで任意のコマンドを実行できます。
nvm exec 4.2 node --version
実行可能ファイルがインストールされている場所へのパスを取得することもできます。
nvm which 12.22
"14.7"、"16.3"、"12.22.1" などのバージョン ポインタの代わりに、、などの次の特別なデフォルト エイリアスを使用できます。
nvm install
nvm use
nvm run
nvm exec
nvm which
node: これにより、
最新バージョンの Node
がインストールされます
iojs: これにより、最新バージョンの IO がインストールされます
.js
stable: このエイリアスは非推奨であり、実際に適用されるのはそれ以前にのみ適用されます。現在、これは のエイリアスです。
node
v0.12
node
unstable:このエイリアスは、最後の「不安定な」ノードリリースを指し、1.0以降、すべてのノードバージョンが安定しています。(SemVerでは、バージョンは安定性ではなく破損を伝えます)。
node
v0.11
ノードに長期サポート(LTS)のスケジュールがある エイリアスやファイル内の LTS バージョンは、最新の LTS や LTS リリースの表記法など、"argon" 行から参照できます。さらに、次のコマンドは LTS 引数をサポートしています。
.nvmrc
lts/*
lts/argon
nvm install --lts/
nvm install --lts=argon/
nvm install 'lts/*'/
nvm install lts/argon
nvm uninstall --lts/
nvm uninstall --lts=argon/
nvm uninstall 'lts/*'/
nvm uninstall lts/argon
nvm use --lts/
nvm use --lts=argon/
nvm use 'lts/*'/
nvm use lts/argon
nvm exec --lts/
nvm exec --lts=argon/
nvm exec 'lts/*'/
nvm exec lts/argon
nvm run --lts/
nvm run --lts=argon/
nvm run 'lts/*'/
nvm run lts/argon
nvm ls-remote --lts/
nvm ls-remote --lts=argon
nvm ls-remote 'lts/*'/
nvm ls-remote lts/argon
nvm version-remote --lts/
nvm version-remote --lts=argon/
nvm version-remote 'lts/*'/
nvm version-remote lts/argon
のローカルコピーが https://nodejs.org に接続するたびに、使用可能なすべてのLTS回線に対して適切なローカルエイリアスが再作成されます。これらのエイリアス ( に格納されている) は によって管理されます。これらのファイルを変更、削除、または作成しないでください。変更が取り消されることを想定し、これらのファイルに干渉すると、サポートされない可能性のあるバグが発生することが予想されます。
nvm
$NVM_DIR/alias/lts
nvm
最新のLTSバージョンのノードを取得し、既存のインストール済みパッケージを移行するには、
nvm install 'lts/*' --reinstall-packages-from=current
新しいバージョンの Node.js をインストールし、以前のバージョンから npm パッケージを移行する場合:
nvm install node --reinstall-packages-from=node
これは最初に「nvmバージョンノード」を使用して、パッケージの移行元の現在のバージョンを識別します。次に、新しいバージョンを解決してリモートサーバーからインストールし、インストールします。最後に、「nvm再インストールパッケージ」を実行して、以前のバージョンのNodeから新しいバージョンにnpmパッケージを再インストールします。
次のように、特定のバージョンのNodeからnpmパッケージをインストールして移行することもできます。
nvm install 6 --reinstall-packages-from=5
nvm install v4.2 --reinstall-packages-from=iojs
パッケージを明示的に再インストールしてもnpmバージョンは更新されないことに注意してください — これは、npmが誤って新しいノードバージョンの壊れたバージョンにアップグレードされないようにするためです。
npmを同時に更新するには、次のようにフラグを追加します。
--latest-npm
nvm install 'lts/*' --reinstall-packages-from=default --latest-npm
または、いつでも次のコマンドを実行して、現在のノードバージョンでサポートされている最新の npm バージョンを取得できます。
nvm install-latest-npm
「npmはNode.jsをサポートしていません」というエラーがすでに発生している場合は、(1)以前のノードバージョンに戻す必要があります(&、(2)新しく作成されたノードバージョンを削除し()、(3)フラグを使用して再実行します。
nvm ls
nvm use <your latest _working_ version from the ls>
nvm uninstall <your _broken_ version of node from the ls>
nvm install
--latest-npm
新しいバージョンをインストールするたびにインストールしたいデフォルトパッケージのリストがある場合は、それもサポートしています -- パッケージ名を 1 行に 1 つずつファイルに追加するだけです。npmがコマンドラインのパッケージ引数として受け入れるものなら何でも追加できます。
$NVM_DIR/default-packages
# $NVM_DIR/default-packages
rimraf
object-inspect@1.0.2
stevemao/left-pad
io.jsをインストールする場合:
nvm install iojs
新しいバージョンの io.js をインストールし、以前のバージョンから npm パッケージを移行する場合:
nvm install iojs --reinstall-packages-from=iojs
ノード内のnpmパッケージの移行について説明したのと同じガイドラインがio.jsにも適用されます。
システムにインストールされたバージョンのノードを使用する場合は、特別なデフォルトエイリアス「system」を使用できます。
nvm use system
nvm run system --version
インストールされているバージョンを確認するには:
nvm ls
インストール可能なバージョンを確認する場合:
nvm ls-remote
バージョンとエイリアス情報の表示に使用する 5 つの色を設定できます。これらの色は、既定の色を置き換えます。 初期色は次のとおりです。
カラーコード:
r/R = red / bold red g/G = green / bold green b/B = blue / bold blue c/C = cyan / bold cyan m/M = magenta / bold magenta y/Y = yellow / bold yellow k/K = black / bold black e/W = light grey / white
nvm set-colors rgBcm
シェルの終了後もカスタムカラーを保持する場合は、シェルプロファイルで変数をエクスポートします。たとえば、シアン、マゼンタ、グリーン、太字の赤、太字の黄色を使用する場合は、次の行を追加します。
NVM_COLORS
export NVM_COLORS='cmgRY'
nvm help (or -h or --help)、、通常はカラー化された出力を生成します。オプションを使用して(または環境変数を設定することによって)色を無効にすることができます:
nvm ls
nvm ls-remote
nvm alias
--no-colors
TERM=dumb
nvm ls --no-colors
nvm help --no-colors
TERM=dumb nvm ls
PATHを復元するには、PATHを非アクティブ化します。
nvm deactivate
新しいシェルで使用するデフォルトのノードバージョンを設定するには、エイリアス「default」を使用します。
nvm alias default node
ノードバイナリのミラーを使用するには、次のように設定します。
$NVM_NODEJS_ORG_MIRROR
export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
nvm install node
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 4.2
io.jsバイナリのミラーを使用するには、次のように設定します。
$NVM_IOJS_ORG_MIRROR
export NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
nvm install iojs-v1.0.3
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
nvm useデフォルトでは、「現在の」シンボリックリンクは作成されません。この動作を有効にするには "true" に設定し、IDE で役立つ場合があります。この環境変数を有効にして複数のシェルタブで使用すると、競合状態が発生する可能性があることに注意してください。
$NVM_SYMLINK_CURRENT
nvm
ノードのバージョン番号 (または理解できるその他の文字列、詳細については「」) を含むファイルをプロジェクトのルートディレクトリ (または任意の親ディレクトリ) に作成できます。 その後、、およびは、コマンドラインでバージョンが指定されていない場合、ファイルで指定されたバージョンを使用します。
.nvmrc
nvm
nvm --help
nvm use
nvm install
nvm exec
nvm run
nvm which
.nvmrc
たとえば、nvm をデフォルトで最新の 5.9 リリース、最新の LTS バージョン、または現在のディレクトリの最新のノードバージョンにするには、次のようにします。
$ echo "5.9" > .nvmrc
$ echo "lts/*" > .nvmrc # to default to the latest LTS version
$ echo "node" > .nvmrc # to default to the latest version
[NB これらの例では、POSIX 準拠のシェル バージョンの .Windows開発環境を使用している場合、たとえばファイルがリモートLinuxデプロイメントの構成に使用される場合は、がコピーされて無効なファイルになることに注意してください。それらを削除します。
echo
cmd
.nvmrc
"
次に、nvmを実行すると:
$ nvm use
Found '/path/to/project/.nvmrc' with version <5.9>
Now using node v5.9.1 (npm v3.7.3)
nvm useら。al. は、ディレクトリ構造を現在のディレクトリから上にトラバースしてファイルを探します。言い換えれば、etを実行します。ディレクトリの任意のサブディレクトリで、 は WILL が利用される結果になります。
.nvmrc
nvm use
.nvmrc
.nvmrc
ファイルの内容は、 ( で記述) の後に改行が続く必要があります。末尾のスペースは許可されず、末尾の改行が必要です。
.nvmrc
<version>
nvm --help
avn
を使用してシェルに深く統合し、ディレクトリを変更するときに自動的に呼び出すことができます。 メンテナによってサポートされていません。avnチームに問題を報告
してください。
nvm
avn
nvm
より軽量なソリューションを好む場合は、以下のレシピがユーザーから提供されています。メンテナによってサポートされていません。ただし、より多くの例のプルリクエストを受け付けています。
nvm
nvm
nvm use
あなたの最後に以下を入れてください:
$HOME/.bashrc
cdnvm() {
command cd "$@" || return $?
nvm_path=$(nvm_find_up .nvmrc | tr -d '\n')
# If there are no .nvmrc file, use the default nvm version
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
declare default_version;
default_version=$(nvm version default);
# If there is no default version, set it to `node`
# This will use the latest version on your machine
if [[ $default_version == "N/A" ]]; then
nvm alias default node;
default_version=$(nvm version default);
fi
# If the current version is not the default version, set it to use the default version
if [[ $(nvm current) != "$default_version" ]]; then
nvm use default;
fi
elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
declare nvm_version
nvm_version=$(<"$nvm_path"/.nvmrc)
declare locally_resolved_nvm_version
# `nvm ls` will check all locally-available versions
# If there are multiple matching versions, take the latest one
# Remove the `->` and `*` characters and spaces
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')
# If it is not already installed, install it
# `nvm install` will implicitly use the newly-installed version
if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
nvm install "$nvm_version";
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
nvm use "$nvm_version";
fi
fi
}
alias cd='cdnvm'
cd "$PWD"
このエイリアスは、ファイルを検出するために現在のディレクトリから「up」を検索します。見つかった場合は、そのバージョンに切り替わります。そうでない場合は、デフォルトバージョンが使用されます。
.nvmrc
nvm use
.nvmrc
これをuに入れて、nvmにどのノードを指示するかを指示する文字列を含むファイルを含むディレクトリに入るたびに自動的に呼び出します。
$HOME/.zshrc
nvm use
.nvmrc
use
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then
nvm use
fi
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
nvm use
.nvmrc
This requires that you have bass installed.
# ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
# ~/.config/fish/functions/nvm_find_nvmrc.fish
function nvm_find_nvmrc
bass source ~/.nvm/nvm.sh --no-use ';' nvm_find_nvmrc
end
# ~/.config/fish/functions/load_nvm.fish
function load_nvm --on-variable="PWD"
set -l default_node_version (nvm version default)
set -l node_version (nvm version)
set -l nvmrc_path (nvm_find_nvmrc)
if test -n "$nvmrc_path"
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
if test "$nvmrc_node_version" = "N/A"
nvm install (cat $nvmrc_path)
else if test "$nvmrc_node_version" != "$node_version"
nvm use $nvmrc_node_version
end
else if test "$node_version" != "$default_node_version"
echo "Reverting to default Node version"
nvm use default
end
end
# ~/.config/fish/config.fish
# You must call it on initialization or listening to directory switching won't work
load_nvm > /dev/stderr
Tests are written in Urchin. Install Urchin (and other dependencies) like so:
npm install
There are slow tests and fast tests. The slow tests do things like install node and check that the right versions are used. The fast tests fake this to test things like aliases and uninstalling. From the root of the nvm git repository, run the fast tests like this:
npm run test/fast
Run the slow tests like this:
npm run test/slow
Run all of the tests like this:
npm test
Nota bene: Avoid running nvm while the tests are running.
nvm exposes the following environment variables:
NVM_DIR- nvm's installation directory.
NVM_BIN- where node, npm, and global packages for the active version of node are installed.
NVM_INC- node's include file directory (useful for building C/C++ addons for node).
NVM_CD_FLAGS- used to maintain compatibility with zsh.
NVM_RC_VERSION- version from .nvmrc file if being used.
Additionally, nvm modifies , and, if present, and when changing versions.
PATH
MANPATH
NODE_PATH
To activate, you need to source :
bash_completion
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
Put the above sourcing line just below the sourcing line for nvm in your profile (, ).
.bashrc
.bash_profile
nvm:
$ nvmTab
alias deactivate install list-remote reinstall-packages uninstall version
cache exec install-latest-npm ls run unload version-remote
current help list ls-remote unalias use which
nvm alias:
$ nvm aliasTab
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
$ nvm alias my_aliasTab
v10.22.0 v12.18.3 v14.8.0
nvm use:
$ nvm useTab
my_alias default v10.22.0 v12.18.3 v14.8.0
nvm uninstall:
$ nvm uninstallTab
my_alias default v10.22.0 v12.18.3 v14.8.0
nvmwill encounter some issues if you have some non-default settings set. (see #606) The following are known to cause issues:
Inside :
~/.npmrc
prefix='some/path'
Environment Variables:
$NPM_CONFIG_PREFIX
$PREFIX
Shell settings:
set -e
In order to provide the best performance (and other optimizations), nvm will download and install pre-compiled binaries for Node (and npm) when you run . The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al).
nvm install X
Alpine Linux, unlike mainstream/traditional Linux distributions, is based on BusyBox, a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - musl. This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that.
nvm install X
There is a flag for which requests nvm download Node source and compile it locally.
-s
nvm install
If installing nvm on Alpine Linux is still what you want or need to do, you should be able to achieve this by running the following from you Alpine Linux shell, depending on which version you are using:
apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (These are all versions on the main branch). Alpine 3.5 - 3.12 required the package python2
to build NodeJS, as they are older versions to build. Alpine 3.13+ requires python3
to successfully build newer NodeJS versions, but you can use python2
with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script.
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
As a potential alternative, @mhart (a Node contributor) has some Docker images for Alpine Linux with Node and optionally, npm, pre-installed.
To remove manually, execute the following:
nvm
$ rm -rf "$NVM_DIR"
Edit (or other shell resource config) and remove the lines below:
~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
To make the development and testing work easier, we have a Dockerfile for development usage, which is based on Ubuntu 18.04 base image, prepared with essential and useful tools for development, to build the docker image of the environment, run the docker command at the root of repository:
nvm
nvm
$ docker build -t nvm-dev .
This will package your current nvm repository with our pre-defined development environment into a docker image named , once it's built with success, validate your image via :
nvm-dev
docker images
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvm-dev latest 9ca4c57a97d8 7 days ago 650 MB
If you got no error message, now you can easily involve in:
$ docker run -h nvm-dev -it nvm-dev
nvm@nvm-dev:~/.nvm$
Please note that it'll take about 8 minutes to build the image and the image size would be about 650MB, so it's not suitable for production usage.
For more information and documentation about docker, please refer to its official website:
If you try to install a node version and the installation fails, be sure to run to delete cached node downloads, or you might get an error like the following:
nvm cache clear
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
Where's my ? Check out #43
sudo node
After the v0.8.6 release of node, nvm tries to install from binary packages. But in some systems, the official binary packages don't work due to incompatibility of shared libs. In such cases, use option to force install from source:
-s
nvm install -s 0.8.6
default
nvm current
system
PATH
nvm.sh)
nvm node version not found in vim shell
If you set node version to a version other than your system node version and open vim and run you should see if you see your system version . You need to run:
nvm use 6.2.1
:!node -v
v6.2.1
v0.12.7
sudo chmod ugo-x /usr/libexec/path_helper
More on this issue in dotphiles/dotzsh.
nvm is not compatible with the npm config "prefix" option
Some solutions for this issue can be found here
There is one more edge case causing this issue, and that's a mismatch between the $HOME
path and the user's home directory's actual name.
You have to make sure that the user directory name in and the user directory name you'd see from running are capitalized the same way (See this issue).
$HOME
ls /Users/
To change the user directory and/or account name follow the instructions here
Homebrew makes zsh directories unsecure
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? y
Homebrew causes insecure directories like and . This is not an problem - it is a homebrew problem. Refer here for some solutions related to the issue.
/usr/local/share/zsh/site-functions
/usr/local/share/zsh
nvm
Macs with M1 chip
Experimental support for the M1 architecture was added in node.js v15.3 and full support was added in v16.0. Because of this, if you try to install older versions of node as usual, you will probably experience either compilation errors when installing node or out-of-memory errors while running your code.
So, if you want to run a version prior to v16.0 on an M1 Mac, it may be best to compile node targeting the Intel architecture so that Rosetta 2 can translate the processor instructions to ARM-based Apple Silicon instructions. Here's what you will need to do:
x86_64
x86_64
Install Rosetta, if you haven't already done so
$ softwareupdate --install-rosetta
You might wonder, "how will my M1 Mac know to use Rosetta for a version of node compiled for an Intel chip?". If an executable contains only Intel instructions, macOS will automatically use Rosetta to translate the instructions.
Open a shell that's running using Rosetta
$ arch -x86_64 zsh
Note: This same thing can also be accomplished by finding the Terminal or iTerm App in Finder, right clicking, selecting "Get Info", and then checking the box labeled "Open using Rosetta".
Note: This terminal session is now running in . If is not the shell you typically use, may not be 'd automatically like it probably is for your usual shell through your dotfiles. If that's the case, make sure to source .
zsh
zsh
nvm
source
nvm
$ source "${NVM_DIR}/nvm.sh"
Install whatever older version of node you are interested in. Let's use 12.22.1 as an example. This will fetch the node source code and compile it, which will take several minutes.
$ nvm install v12.22.1 --shared-zlib
Note: You're probably curious why is included. There's a bug in recent versions of Apple's system compiler. If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the flag. However, later, when you attempt to something using your old version of node.js, you will see errors. If you want to avoid the possible hassle of dealing with this, include that flag. For more details, see this issue and this comment
--shared-zlib
clang
--shared-zlib
npm install
incorrect data check
Exit back to your native shell.
$ exit
$ arch
arm64
Note: If you selected the box labeled "Open using Rosetta" rather than running the CLI command in the second step, you will see here. Unless you have another reason to have that box selected, you can deselect it now.
i386
Check to make sure the architecture is correct. is the abbreviation for , which is what you want to see.
x64
x86_64
$ node -p process.arch
x64
Now you should be able to use node as usual.
If you've encountered this error on WSL-2:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com
It may be due to your antivirus, VPN, or other reasons.
Where you can while you can't
ping 8.8.8.8
ping google.com
This could simply be solved by running this in your root directory:
sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf
これにより、WSL の実行時に自動的に生成されるファイルが削除され、新しいファイルが作成されて put 、ファイルが作成され、そのファイルの自動生成が防止されます。
resolve.conf
nameserver 8.8.8.8
wsl.conf
[network]
generateResolveConf = false
ファイルの内容を確認するには、次のコマンドを実行します。
cat /etc/resolv.conf
現在、唯一のメンテナは@ljharbです - より多くのメンテナを歓迎しており、時間の経過とともにチームに人々を追加したいと考えています。ガバナンスは、プロジェクトの進展に合わせて再評価されます。
LICENSE.md を参照してください。
著作権OpenJS財団と貢献者。全著作権所有。OpenJS財団は登録商標を有し、商標を使用しています。OpenJS財団の商標のリストについては、商標ポリシーと商標リストをご覧ください。Node.jsはJoyent, Inc.の商標であり、その許可を得て使用しています。OpenJS Foundationの商標リストに記載されていない商標およびロゴは、それぞれの所有者の商標™または登録商標®です。それらの使用は、それらとの提携またはそれらによる承認を意味するものではありません。
nvm
OpenJS Foundation |利用規約 |プライバシーポリシー |OpenJS財団細則 |商標ポリシー|商標リスト |クッキーポリシー