node.js 节点已经安装,只是没有链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35249204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:52:58  来源:igfitidea点击:

Node already installed, it's just not linked

node.jsmacoshomebrew

提问by Ela

I tried to fix the error where you have to use sudo when running npm. I blindly followed a link to uninstall node, the code was from this gist

我试图修复运行 npm 时必须使用 sudo 的错误。我盲目地按照链接卸载节点,代码来自这个要点

After running the command and I tried to install it back with brew: brew install node. Which gave me the following error:

运行命令后,我尝试使用 brew: 重新安装它brew install node。这给了我以下错误:

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
/usr/local/share/doc/node is not writable.

You can try again using:
  brew link node

Trying to run brew link node, I got:

试图运行brew link node,我得到:

Linking /usr/local/Cellar/node/5.4.0... 
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.

Then when I write brew install npm, I get:

然后当我写brew install npm,我得到:

Warning: node-5.4.0 already installed, it's just not linked

When I write npm -vI get:

当我写npm -v我得到:

env: node: No such file or directory

Any ideas on how to solve this?

关于如何解决这个问题的任何想法?

回答by Ela

I managed to fix this by first running sudo chown -R $USER /usr/localand following it with brew link node. Now I have node properly installed.

我设法通过首先运行sudo chown -R $USER /usr/local并使用brew link node. 现在我已经正确安装了节点。

回答by desloovere_j

This solution works! It is a combination of all the combinations.

此解决方案有效!它是所有组合的组合。

Fix it using the following code.

使用以下代码修复它。

  1. sudo chmod 776 /usr/local/lib
  2. brew link --overwrite node

    Outputs: Linking /usr/local/Cellar/node/9.6.1... 49 symlinks created

  3. sudo chmod 755 /usr/local/lib
  1. sudo chmod 776 /usr/local/lib
  2. brew link --overwrite node

    输出: Linking /usr/local/Cellar/node/9.6.1... 49 symlinks created

  3. sudo chmod 755 /usr/local/lib

回答by NGR

  1. sudo chown -R $USER /usr/local
  2. brew link --overwrite node
  1. 须藤 chown -R $USER /usr/local
  2. brew link --overwrite 节点

回答by Debiprasad

If you are on High Sierra, then sudo chown -R $USER /usr/localwon't work. Instead use:

如果您在 High Sierra 上,则sudo chown -R $USER /usr/local无法使用。而是使用:

sudo chown -R $(whoami) $(brew --prefix)/*

Source: https://github.com/Homebrew/brew/issues/3228#issuecomment-332679274

来源:https: //github.com/Homebrew/brew/issues/3228#issuecomment-332679274

回答by Basavaraj Hadimani

for OSX High Sierra users:

对于 OSX High Sierra 用户:

sudo chown -R $(whoami) $(brew --prefix)/*

brew link --overwrite node

then check node -v and npm -v

然后检查 node -v 和 npm -v

回答by Waleed Youssry Fahmy

Change /usr/local permission to your user:

将 /usr/local 权限更改为您的用户:

sudo chown -R $USER /usr/local

Then run brew postinstall:

然后运行 ​​brew postinstall:

brew postinstall node

Now you're done. To check:

现在你完成了。去检查:

npm -v

Extra step: run brew doctor for cleaning purpose

额外步骤:运行 brew doctor 进行清洁

brew doctor

You might need to prune some extra old stuff if doctor find it.

如果医生发现,您可能需要修剪一些额外的旧东西。

回答by Dr. Freddy Dimethyltryptamine

You have to allow it to be overwritten. Whatever directory is not writable

您必须允许它被覆盖。任何目录都不可写

For example, if its /usr/lib/dtrace

例如,如果它的 /usr/lib/dtrace

sudo chown -R `whoami`:admin /usr/lib/dtrace

And then

进而

brew link --overwrite node

Fixes it

修复它

回答by MoD

For Mojave || Catalina use:

对于莫哈韦|| 卡特琳娜用途:

sudo chown -R $(whoami) $(brew --prefix)

brew link --overwrite node

回答by SylvesterAbreuLoreto

I did have the same issue when I was brew link jqbut refering to /usr/local/lib is not writable. In one of my machines I couldn't apply Ela suggestion. I did sudo chmod 776 /usr/local/libthen I did brew link jqwhich was successful and then changed it back to sudo chmod 755 /usr/local/lib.

我确实遇到了同样的问题,brew link jq但参考/usr/local/lib is not writable. 在我的一台机器上,我无法应用 Ela 的建议。我做到了sudo chmod 776 /usr/local/lib然后我做到了brew link jq,这是成功的,然后将其改回sudo chmod 755 /usr/local/lib.

回答by avivamg

In this case, Apparently you're struggling with 2 versions in your machine and You should link pointer to the right version, Try installing again node and Unlink the previous version and Link the new one.

在这种情况下,显然您的机器中存在 2 个版本,您应该将指针链接到正确的版本,尝试再次安装节点并取消链接先前版本并链接新版本

brew install node
brew link --overwrite node

//If it already linked
brew unlink node && brew link node