卸载

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

删除完成,检查是否安装成功,没有的话,重新安装。

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐