背景:由于电脑中装了好几个前端vue项目,但是每个vue项目都依赖不同的node版本,所以打算安装一个node版本控制工具来随时切换node的版本
下载nvm的网址
javascript
https://nvm.uihtm.com/
下载nvm的命令
javascript
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash INT|INT ✘ base Py at 13:47:26
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15916 100 15916 0 0 38473 0 --:--:-- --:--:-- --:--:-- 38819
=> Downloading nvm from git to '/Users/wuzhanxi/.nvm'
=> Cloning into '/Users/wuzhanxi/.nvm'...
remote: Enumerating objects: 380, done.
remote: Counting objects: 100% (380/380), done.
remote: Compressing objects: 100% (323/323), done.
remote: Total 380 (delta 43), reused 178 (delta 29), pack-reused 0 (from 0)
Receiving objects: 100% (380/380), 382.75 KiB | 235.00 KiB/s, done.
Resolving deltas: 100% (43/43), done.
* (HEAD detached at FETCH_HEAD)
master
=> Compressing and cleaning up git repository
=> Appending nvm source string to /Users/wuzhanxi/.zshrc
=> Appending bash_completion source string to /Users/wuzhanxi/.zshrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
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
仔细看上面的输出,它将相应的配置放到下面的文件中 /Users/wuzhanxi/.zshrc
javascript
cat /Users/wuzhanxi/.zshrc
但是这会儿在终端下执行nvm的命令,会提示该命令不生效
javascript
~/Desktop nvm 127 ✘ base Py at 13:50:03
zsh: command not found: nvm
原因是上面的配置文件没有生效,解决方案,执行下面的命令,让配置文件立即生效
javascript
source /Users/wuzhanxi/.zshrc
然后再次执行nvm即可
javascript
nvm
展示远程上的可用node版本
javascript
nvm list-remote
安装特定版本的node
javascript
nvm install 16.17.1 3 ✘ base Py at 14:11:16
Downloading and installing node v16.17.1...
Downloading https://nodejs.org/dist/v16.17.1/node-v16.17.1-darwin-arm64.tar.xz...
############################################################################################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v16.17.1 (npm v8.15.0)
Creating default alias: default -> 16.17.1 (-> v16.17.1)
展示已经安装的node版本
javascript
nvm list
使用特定的node版本
javascript
nvm use xxx
设置默认的node版本
javascript
nvm alias default 16.17.1
查看当前使用的node版本
javascript
node -v
有疑问,输入展示可用的node版本列表后,显示以下两种不同的效果
nvm list-remote
javascript
v16.10.0
v16.11.0
v16.11.1
v16.12.0
v16.13.0 (LTS: Gallium)
v16.13.1 (LTS: Gallium)
v16.13.2 (LTS: Gallium)
v16.14.0 (LTS: Gallium)
v16.14.1 (LTS: Gallium)