ubuntu下使用nvm安装各种版本的node

git clone nvm

直接从 github clone nvm 到本地, 这里假设大家都使用 ~/git 目录存放 git 项目:

$ cd ~/git
$ git clone https://github.com/creationix/nvm.git

配置终端启动时自动执行 source ~/git/nvm/nvm.sh,在 ~/.bashrc, ~/.bash_profile, ~/.profile, 或者 ~/.zshrc 文件添加以下命令:

source ~/git/nvm/nvm.sh

重新打开你的终端, 输入 nvm

twitch@laravel:~$ nvm

Node Version Manager

Note:  refers to any version-like string nvm understands. This includes:
  - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  - default (built-in) aliases: node, stable, unstable, iojs, system
  - custom aliases you define with `nvm alias foo`

 Any options that produce colorized output should respect the `--no-colors` option.

Usage:
  nvm --help                                Show this message
  nvm --version                             Print out the latest released version of nvm
  nvm install [-s]                 Download and install a , [-s] from source. Uses .nvmrc if available
    --reinstall-packages-from=     When installing, reinstall packages installed in 
    --lts                                   When installing, only select from LTS (long-term support) versions
    --lts=                        When installing, only select from versions for a specific LTS line
  nvm uninstall                    Uninstall a version
  nvm uninstall --lts                       Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
  nvm uninstall --lts=            Uninstall using automatic alias for provided LTS line, if available.
  nvm use [--silent]               Modify PATH to use . Uses .nvmrc if available
    --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=                        Uses automatic alias for provided LTS line, if available.
  nvm exec [--silent]  [] Run  on . Uses .nvmrc if available
    --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=                        Uses automatic alias for provided LTS line, if available.
  nvm run [--silent]  []     Run `node` on  with  as arguments. Uses .nvmrc if available
    --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=                        Uses automatic alias for provided LTS line, if available.
  nvm current                               Display currently activated version
  nvm ls                                    List installed versions
  nvm ls                           List versions matching a given 
  nvm ls-remote                             List remote versions available for install
    --lts                                   When listing, only show LTS (long-term support) versions
  nvm ls-remote                    List remote versions available for install, matching a given 
    --lts                                   When listing, only show LTS (long-term support) versions
    --lts=                        When listing, only show versions for a specific LTS line
  nvm version                      Resolve the given description to a single local version
  nvm version-remote               Resolve the given description to a single remote version
    --lts                                   When listing, only select from LTS (long-term support) versions
    --lts=                        When listing, only select from versions for a specific LTS line
  nvm deactivate                            Undo effects of `nvm` on current shell
  nvm alias []                     Show all aliases beginning with 
  nvm alias                  Set an alias named  pointing to 
  nvm unalias                         Deletes the alias named 
  nvm reinstall-packages           Reinstall global `npm` packages contained in  to current version
  nvm unload                                Unload `nvm` from shell
  nvm which []                     Display path to installed node version. Uses .nvmrc if available
  nvm cache dir                             Display path to the cache directory for nvm
  nvm cache clear                           Empty cache directory for nvm

Example:
  nvm install v0.10.32                  Install a specific version number
  nvm use 0.10                          Use the latest available 0.10.x release
  nvm run 0.10.32 app.js                Run app.js using node v0.10.32
  nvm exec 0.10.32 node app.js          Run `node app.js` with the PATH pointing to node v0.10.32
  nvm alias default 0.10.32             Set default node version on a shell

Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

通过 nvm 安装任意版本的 node
nvm 默认是从 http://nodejs.org/dist/ 下载的,国外服务器, 必然很慢,好在 nvm 以及支持从镜像服务器下载包, 于是我们可以方便地从七牛的 node dist 镜像下载:

$ NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node nvm install 4

于是你就会看到一段非常快速进度条:
######################################################################## 100.0%Now using node v4.6.1

如果你不想每次都输入环境变量 NVM_NODEJS_ORG_MIRROR, 那么我建议你加入到 .bashrc 文件中:

# nvm
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/nodesource ~/git/nvm/nvm.sh

然后你可以继续非常方便地安装各个版本的 node 了, 你可以查看一下你当前已经安装的版本:

twitch@laravel:~$ nvm ls
 ->       v4.6.1
default -> 4 (-> v4.6.1)
node -> stable (-> v4.6.1) (default)
stable -> 4.6 (-> v4.6.1) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> N/A)
lts/argon -> v4.6.1
lts/boron -> v6.9.1 (-> N/A)

windows 环境

多版本nodejs管理工具nvmfor windows

通过 nvm 安装任意版本的 node

nvm 默认是从 http://nodejs.org/dist/ 下载的,国外服务器, 必然很慢,npm也是从国外服务器下载的,基本下载不下来好在 nvm 以及支持从镜像服务器下载包, 于是我们可以方便地从淘宝的 node dist 镜像下载:

set "NVMW_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node"set "NVMW_NPMJS_COM_MIRROR=https://npm.taobao.org/mirrors/npm"nvm install 4.3.2

你可能感兴趣的:(ubuntu下使用nvm安装各种版本的node)