Node版本管理器:nvm

jopen 10年前發布 | 196K 次閱讀 nvm Node.js 開發

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.

項目主頁:http://www.baiduhome.net/lib/view/home/1418097373136

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!