一、卸載掉電腦上的node(如果沒有,請到下一步)
mac卸載node,參考http://www.itdecent.cn/p/88cd55296983
如果可以訪問github,請查看官網(wǎng)教程
二、輸入如下命令安裝
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
三、驗(yàn)證
打開終端,輸入
command -v nvm
如果輸出nvm,則成功,否則,不成功(可參考原文教程)
問題
-
nvm: command not found
可能缺少.bash_profile文件,執(zhí)行touch ~/.bash_profile添加該文件;然后執(zhí)行安裝命令;再執(zhí)行source ~/.bash_profile - 其他問題可以看官網(wǎng)教程或者我本地的readme.md
- 其他安裝方法:
http://www.itdecent.cn/p/cb7cd2e8ede0
jianshu.com/p/19c0351824bb
nvm使用教程
$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
v16.9.1
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
v14.18.0
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v
v12.22.6
nvm run 6.10.3 app.js Run app.js using node 6.10.3
nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3
nvm alias default 8.1.0 Set default node version on a shell
nvm alias default node Always default to the latest available node version on a shell
nvm install node Install the latest available version
nvm use node Use the latest version
nvm install --lts Install the latest LTS version
nvm use --lts Use the latest LTS version
nvm set-colors cgYmW Set text colors to cyan, green, bold yellow, magenta, and white
更換nvm源
- 打開終端
- 輸入
open ~/.zshrc - 在打開的文本編輯器里面,最下面添加下述代碼
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
解決nvm切換node版本后,重新打開終端失效
使用nvm alias default 18來切換