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

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

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

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

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

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

195198 次浏览

The PATH variable holds a list of directories separated by colons, so if you want to add more than one directory, just put a colon between them:

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

这种语法适用于任何与 Bourne 兼容的 shell (sh、 ksh、 bash、 zsh...)。但是 zsh 是 MacOS 最新版本中的默认 shell,它也以另一种方式公开 PATH ——作为一个名为(小写) $path的变量,它是一个数组,而不是单个字符串。所以你可以这样做:

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

In either case, you may want to check to make sure the directory isn't already in the PATH before adding it. Here's what that looks like using the generic syntax:

for dir in /usr/local/git/bin /usr/local/bin; do
case "$PATH" in
$dir:*|*:$dir:*|*:$dir) :;; # already there, do nothing
*) PATH=$PATH:$dir          # otherwise add it
esac
done

And here's a zsh-specific version:

for dir in /usr/local/git/bin /usr/local/bin; do
if (( ${path[(i)$dir]} > $#path )); then
path+=($dir)
fi
done

但是在 Zsh 中,您也可以将数组 vars 标记为只接受唯一的条目:

typeset -TU PATH path

甚至可以在数组中镜像自己的路径变量:

typeset -TU PYTHONPATH pythonpath

尝试将 $PATH 放在末尾。

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

我对你也有同样的问题。

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

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

cd ~/
touch .bash_profile
open .bash_profile

这将打开。在编辑器中的 bash _ profile 中,在将所需内容添加到按列分隔每个值的路径之后,在以下内容中写入。

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

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

在 MAC OS Catalina, 这些都是对我有效的步骤,所有以上的解决方案都有帮助,但没有解决我的问题。

  1. 检查 node —— version,仍然使用旧版本。
  2. Cd ~/
  3. Bash _ profile
  4. 删除指向旧节点的 $PATH 在我的例子中是/usr/local/bin/node/@node8
  5. Add & save this to $PATH instead "export PATH=$PATH:/usr/local/git/bin:/usr/local/bin"
  6. 关闭所有应用程序使用节点(终端,模拟器,浏览器展览等)
  7. 重新启动终端和检查节点——版本