Node版本管理器:nvm
Node版本管理器:nvm。简单的bash脚本来管理多个活跃的node.js版本。
Installation
First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work.
Note: nvm
does not support Windows (see #284). Two alternatives exist, which are not supported nor developed by us:
Install script
To install you could use the install script using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
The script clones the nvm repository to ~/.nvm
and adds the source line to your profile (~/.bash_profile
, ~/.zshrc
or ~/.profile
).
You can customize the install source, directory and profile using the NVM_SOURCE
, NVM_DIR
, and PROFILE
variables. Eg: curl ... | NVM_DIR=/usr/local/nvm bash
for a global install.
NB. The installer can use git
, curl
, or wget
to download nvm
, whatever is available.
Manual install
For manual install create a folder somewhere in your filesystem with the nvm.sh
file inside it. I put mine in a folder called nvm
.
Or if you have git
installed, then just clone it, and check out the latest version:
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
To activate nvm, you need to source it from your shell:
source ~/.nvm/nvm.sh
I always add this line to my ~/.bashrc
, ~/.profile
, or ~/.zshrc
file to have it automatically sourced upon login. Often I also put in a line to use a specific version of node.
Usage
You can create an .nvmrc
file containing version number in the project root directory (or any parent directory).nvm use
, nvm install
, nvm exec
, and nvm run
will all respect an .nvmrc
file.
To download, compile, and install the latest v0.10.x release of node, do this:
nvm install 0.10
And then in any new shell just use the installed version:
nvm use 0.10
Or you can just run it:
nvm run 0.10 --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 0.10 node --version
In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
nvm install stable nvm install unstable nvm use stable nvm run unstable --version
If you want to use the system-installed version of node, you can use the special default alias "system":
nvm use system nvm run system --version
If you want to see what versions are installed:
nvm ls
If you want to see what versions are available to install:
nvm ls-remote
To restore your PATH, you can deactivate it.
nvm deactivate
To set a default Node version to be used in any new shell, use the alias 'default':
nvm alias default stable
To use a mirror of the node binaries, set $NVM_NODEJS_ORG_MIRROR
:
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10 NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10
nvm use
will not, by default, create a "current" symlink. Set $NVM_SYMLINK_CURRENT
to "true" to enable this behavior, which is sometimes useful for IDEs.