卸載
1. 查看當前安裝的node版本:
node -v
2. 卸載node:
brew uninstall node@版本號 --force
比如安裝的是12.18.1,使用brew uninstall node@12 --force。
還有另外兩種現在不能用的方法:
- 使用brew uninstall node,會報錯:
Error: No such keg: /usr/local/Cellar/node
- brew uninstall node --force不起作用。
3. 刪除配置的環境變量
touch ~/.bash_profile 顯示隱藏的.bash_profile文件
open ~/.bash_profile 打開.bash_profile文件,並刪除裏邊的有關node的配置並保存
source ~/.bash_profile 執行.bash_profile文件使生效。
運行第2步之後,運行node -v 發現會報:
-bash: /usr/local/opt/node@12/bin/node: No such file or directory
這種情況就是配置的環境變量沒有刪除。
安裝
1. 查看本機可安裝的node版本:
brew search node
可以安裝的版本有10、12。後邊打勾的是已經安裝的。
2.安裝node
brew install node@10
3. 鏈接(很重要,否則node不能使用)
brew link node@10
4. 鏈接之後會報兩個建議希望你執行兩個命令,按照執行就好了。
brew link node@10 --force
echo ‘export PATH="/usr/local/opt/node@10/bin:$PATH"’ >> /Users/shenqinci/.bash_profile
5.檢查是否安裝成功
node -v
如果成功,會顯示你安裝的版本號。
有時會報錯誤:
-bash: node: command not found
一般有兩個原因:
- mac剛升級了10.15.0以上版本,解決方案:升級brew。
brew update
升級後,檢查是否安裝成功,沒有的話,重新安裝。
- 卸載過程中出錯,導致有文件衝突。 解決方案:診斷有哪些衝突文件,刪除。
brew doctor
刪除完成,檢查是否安裝成功,沒有的話,重新安裝。