简体   繁体   English

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

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

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/bin to export PATH=$PATH:/usr/local/git/bin ?如何添加/usr/local/bin以导出PATH=$PATH:/usr/local/git/bin

This works in either bash (which is the default shell pre-Catalina) or zsh (which is the default shell from Catalina onward):这适用于 bash(这是 Catalina 之前的默认 shell)或 zsh(这是 Catalina 以后的默认 shell):

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

In zsh you can also do this for the same result:在 zsh 中,您也可以为相同的结果执行此操作:

path+=(/usr/local/git/bin /usr/local/bin) 

尝试将 $PATH 放在最后。

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

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保存,退出,重新启动您的终端并享受

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”。

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

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.检查节点 --version,仍然使用旧的。
  2. cd ~/光盘~/
  3. atom .bash_profile原子 .bash_profile
  4. Remove the $PATH pointing to old node version, in my case it was /usr/local/bin/node/@node8删除指向旧节点版本的 $PATH,在我的情况下它是 /usr/local/bin/node/@node8
  5. Add & save this to $PATH instead "export PATH=$PATH:/usr/local/git/bin:/usr/local/bin"添加并保存到 $PATH 而不是“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重新启动终端并检查节点 --version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用ActivePerl 5.20 Mac OS X(/ usr / bin / perl)而不是/ usr / local / ActivePerl…的默认路径? - How to use default path for ActivePerl 5.20 Mac OS X (/usr/bin/perl) instead of /usr/local/ActivePerl…? 将/ usr / local / bin添加到从MAC OS上运行的JAVA中的System.getenv(“ PATH”)获取的$ PATH中 - add /usr/local/bin to $PATH got from System.getenv(“PATH”) in JAVA run on MAC OS 路径,/usr/bin/ 和 /usr/local/bin/ - Path, /usr/bin/ and /usr/local/bin/ Mac的Git安装程序:为什么/ usr / local / git / bin在我的PATH中? - Git installer for Mac: Why is /usr/local/git/bin in my PATH? 确保 /usr/local/bin 在 mac 上的 $PATH 中 - Making sure /usr/local/bin is in my $PATH on mac Mac 上的 jenkins,路径设置不正确,没有 /usr/local/bin - jenkins on Mac, PATH is not set right, no /usr/local/bin $ usr是正确的/ usr / bin /在/ usr / local / bin /之前 - /usr/bin/ before /usr/local/bin/ while $PATH is correct $ PATH中的/ usr / bin和/ usr / local / bin等的顺序 - Order of /usr/bin and /usr/local/bin and more in $PATH 自制链接python到/ usr / local / bin /在Mac上 - Homebrew link python to /usr/local/bin/ on Mac 在Mac OSX上将/ usr / local / bin(homebrew)添加到pt-config的QtCreator搜索路径 - Adding /usr/local/bin (homebrew) to QtCreator search path for pkg-config on Mac OSX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM