如何解决旧版本的node和npm卸载不干净导致的用homebrew安装新版本过程中出现的问题

本文记录了在尝试通过homebrew安装新版本node和npm时,由于旧版本未完全卸载导致的问题及解决步骤。在安装过程中遇到`brew link`失败,提示存在冲突文件。通过删除冲突文件并使用`sudo chown`命令更改文件所有权,最终成功安装了node和npm。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近发现了homebrew的诸般便利,并且发现自己手动更新node和npm总是不是网络有问题就是什么有问题,动心把之前安装的node和npm手动都删掉了,高高兴兴地去用homebrew安装,结果发现高兴早了还有好多文件没删干净,这些在安装后报错并给提示,我就顺着它的提示一步步解决错误的地方,最后终于安装成功了,具体怎么解决这些错误就在这里记录一下。

一开始的错误是这样的:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d

这里其实就是说,需要把这五个文件全部删掉,但是不能直接输入rm + file,这里给出了这样的回复override rw-r--r--  root/wheel for /usr/local/share/doc/node/gdbinit? 我太菜了也不知道要怎么答,所以在网上一查,原因应该是we should take back the ownership of files and directories under /usr/local, 使用如下命令就可以了:

sudo chown -R `whoami`:admin /usr/local/share/doc/node/gdbinit /usr/local/share/doc/node/lldb_commands.py /usr/local/share/man/man1/node.1 /usr/local/share/systemtap/tapset/node.stp /usr/local/lib/dtrace/node.d

之后再输入brew link node,就会出现

Linking /usr/local/Cellar/node/17.7.1... 7 symlinks created.

就意味着node & npm已经顺利安装啦(撒花)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值