官方地址https://github.com/nvm-sh/nvm/blob/master/README.md#installing-and-updating
**
安装、终端运行命令
**
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
注意版本,一定要去官方文档安装最新版本
开始排错
- 报错(报错bash: line 1: 404:: command not found)
打开配置文件
把这段加上,这是官网的内容,一定要去官网查看文档
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nv
Running either of the above commands downloads a script and runs it.
The script clones the nvm repository to ~/.nvm, and attempts to add
the source lines from the snippet below to the correct profile file
(~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
- 在终端更新刚配置的环境变量,这个挺重要的
source .bash_profile
排错完成执行 安装、终端运行命令,
- 报错443 raw.githubusercontent.com
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
报错原因
github 的一些域名的 DNS 解析被污染,导致DNS 解析过程无法通过域名取得正确的IP地址。
1、获取正确的IP地址
打开 https://www.ipaddress.com/ 输入访问不了的域名
2、打开hosts文件,修改配置
把这段IP地址加上,保存文件到桌面,名字与hosts文件相同,然后拖到etc文件夹,替换hosts文件
199.232.96.133 raw.githubusercontent.com
全部排错完成
nvm命令
nvm install stable ## 安装最新稳定版 node nvm install ## 安装指定版本 nvm
uninstall ## 删除已安装的指定版本,语法与install类似 nvm use ##
切换使用指定的版本node nvm ls ## 列出所有安装的版本 nvm ls-remote ## 列出所有远程服务器的版本(官方node
version list) nvm current ## 显示当前的版本 nvm alias ##
给不同的版本号添加别名 nvm unalias ## 删除已定义的别名 nvm reinstall-packages
## 在当前版本 node 环境下,重新全局安装指定版本号的 npm 包 nvm 所有命令 自行logo