node.js 如何在 Mac 上的 $PATH 中添加 /usr/local/bin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11025980/
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 15:52:18  来源:igfitidea点击:

How to add /usr/local/bin in $PATH on Mac

macosgitnode.jspathprofile

提问by shin

When I do 'open .profile' in the terminal I have the following:

当我在终端中“打开 .profile”时,我有以下内容:

export PATH=$PATH:/usr/local/git/bin 

Now I installed node.js for Mac and it says,

现在我为 Mac 安装了 node.js,它说,

Make sure that /usr/local/bin is in your $PATH.

确保 /usr/local/bin 在您的 $PATH 中。

How can I add /usr/local/binto export PATH=$PATH:/usr/local/git/bin?

如何添加/usr/local/bin到导出PATH=$PATH:/usr/local/git/bin

回答by Mark Reed

export PATH=$PATH:/usr/local/git/bin:/usr/local/bin

One note: you don't need quotation marks here because it's on the right hand side of an assignment, but in general, and especially on Macs with their tradition of spacy pathnames, expansions like $PATHshould be double-quoted as "$PATH".

一注:你不需要引号这里,因为它是在一个赋值的右手边,但在一般情况下,尤其是在与他们的spacy路径名的传统的Mac电脑,喜欢扩张$PATH应该是双引号的"$PATH"

回答by sushil

Try placing $PATH at the end.

尝试将 $PATH 放在最后。

export PATH=/usr/local/git/bin:/usr/local/bin:$PATH

回答by Daniel Raouf

To make the edited value of path persists in the next sessions

使路径的编辑值在下一个会话中保持不变

cd ~/
touch .bash_profile
open .bash_profile

That will open the .bash_profile in editor, write inside the following after adding what you want to the path separating each value by column.

这将在编辑器中打开 .bash_profile,在将您想要的内容添加到按列分隔每个值的路径后,在以下内容中写入。

export PATH=$PATH:/usr/local/git/bin:/usr/local/bin:

Save, exit, restart your terminal and enjoy

保存,退出,重新启动您的终端并享受

回答by GuangYu Yang

I've had the same problem with you.

我和你有同样的问题。

cd to ../etc/ then use ls to make sure your "paths" file is in , vim paths, add "/usr/local/bin" at the end of the file.

cd 到 ../etc/ 然后使用 ls 确保你的“路径”文件在 vim 路径中,在文件末尾添加“/usr/local/bin”。

回答by american-ninja-warrior

I tend to find this neat

我倾向于觉得这很整洁

sudo mkdir -p /etc/paths.d   # was optional in my case
echo /usr/local/git/bin  | sudo tee /etc/paths.d/mypath1

回答by NadZ

In MAC OS Catalina,this are the steps that worked for me, all the above solutions did help but didn't solve my problem.

在 MAC OS Catalina 中,这是对我有用的步骤,上述所有解决方案确实有帮助,但没有解决我的问题。

  1. check node --version, still the old one in use.
  2. cd ~/
  3. atom .bash_profile
  4. Remove the $PATH pointing to old node version, in my case it was /usr/local/bin/node/@node8
  5. Add & save this to $PATH instead "export PATH=$PATH:/usr/local/git/bin:/usr/local/bin"
  6. Close all applications using node (terminal, simulator, browser expo etc)
  7. restart terminal and check node --version
  1. 检查节点 --version,仍然使用旧的。
  2. 光盘~/
  3. 原子 .bash_profile
  4. 删除指向旧节点版本的 $PATH,在我的情况下它是 /usr/local/bin/node/@node8
  5. 添加并保存到 $PATH 而不是“export PATH=$PATH:/usr/local/git/bin:/usr/local/bin”
  6. 使用节点关闭所有应用程序(终端、模拟器、浏览器博览会等)
  7. 重新启动终端并检查节点 --version