curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
这步会自动在你的文件中添加nvm配置文件. 如果你用的是zsh, 那就是 ~/.zshrc. 如果你用的 bash,那就是 ~/.bash_profile…或者其他文件
如果没有自动安装nvm配置文件,你可以自己添加以下内容到你的文件
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
如果你没有这个文件, 则新建
touch ~/.bashrc
使用系统默认文本编辑器(TextEdit):
open -t ~/.bashrc
然后把上面那段放进去
最后执行
source ~/.bashrc
查看有没安装成功
nvm -v
nvm(Node Version Manager)是一个用于在不同版本之间轻松切换Node.js环境的工具,特别是在Unix/Linux和macOS系统上。以下是一些常用的nvm命令及其解释:
https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/