Node Version Manager
前言
NVM,一个你开始感觉可有可无,后来必须装一个的 node 版本管理工具。反正现在用不到,到时候再说吧… 好吧,真香系列。其实本地安装ghost时指定了node版本,好吧,是时候装一个nvm了。
但是 nvm 不支持 windows,所以以下内容基于 macos。windows 可以选择nvm-windows 或者 n
安装
# using cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
# using Wgit
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
最新版本可查看官方nvm
The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
nvm 文件在~/.nvm 目录下, 环境变量配置需要加到(~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc)文件中。
我使用的oh-my-zsh,所以修改~/.zshrc配置文件。打开~/.zshrc,添加:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
# 重启配置
source ~/.zshrc
# 输入nvm试试,有反应就恭喜你成功了
nvm
...
使用
install 安装
nvm install node # “node”是最新版本的别名
nvm install v10.13.0
ls 查看安装版本
nvm ls
nvm ls-romote # 查看可安装版本
use 使用制定版本
node use 6.14.4
deactivate 恢复 PATH,停用
nvm deactivate
Bash completion
nvm tag提示,需要手动配置,打开~/.zshrc,在上述的后面添加:
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
更多使用nvm
## 最后
关于nvm和n的选择问题。我不说🙊。