https://github.com/creationix/nvm
nvm 讓我們可以方便地安裝切換不同的 nodejs 環境 並且不需要 root 權限
List Node.js LTS version
nvm ls-remote --lts
nvm install --lts
nvm install --lts=Boron
# lts/* denote the lastest LTS
num install 'lts/*'
nvm use 'lts/*'
nvm use lts/boron
nvm which lts/boron
nvm ls
what versions are installed
Special default aliases ( in place of a version pointer like "5.0", "4.2.1")
node: refers to the latest version of node
iojs: refers to the latest version of io.js
system: refers to the system-installed version of node
# restore your PATH
nvm deactivate
# set a default Node version to be used in any new shell
nvm alias default node
System version of node
# use the system-installed version of node
# "system" is the special default alias
nvm use system
#To set a default Node version to be used in any new shell, use the alias 'default'
# node: refers to the latest version of node
nvm alias default node
.nvmrc
echo "5.9" > .nvmrc
echo "lts/*" > .nvmrc # to default to the latest LTS version
nvm use
安裝 nvm
如果你是 oh-my-zsh 的使用者
nvm 的安裝 可以透過 oh-my-zsh 的 plugin 機制
git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
設定 $HOME/.zshrc
#load as a plugin in your .zshrc
plugins+=(zsh-nvm)