安装homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装nvm
$ brew install nvm
设置.bash_profile
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
参考:http://my.oschina.net/homeemail?disp=2&p=1&catalog=542671
以mac下为例,前提:以安装git
gitclonegit@github.com:creationix/nvm.git /.nvm source ~/.nvm/nvm.sh
安装
$ nvm install v0.12.0
显示当前本地安装的所有 Node.js
$ nvm ls
显示服务器所有可用的 Node.js
$ nvm ls-remote
本地可用的 Node.js 中使用 0.12.0
$ nvm use 0.12.0
设置每次启动默认版本
$ nvm alias default 0.12.0
查看正在使用的版本
$ nvm current
v0.10.24
以指定版本执行脚本
$ nvm run 0.10.24 myApp.js
卸载nvm
$ rm -rf ~/.nvm
注意,如果重启终端后,出现nvm command not found
解决方案:
Check your .bash_profile or .profile file. You most likely had a problem during the installation.
You should have the following at the end of one of those files.
[[ -s HOME/.nvm/nvm.sh ]] && .HOME/.nvm/nvm.sh # This loads NVM
在当前用户的home目录里有个.bash_profile,如果没有建一个
touch .bash_profile
编辑.bash_profile
vim .bash_profile