我已经阅读了几个关于如何在OSX上永久设置环境变量的答案。

首先,我尝试了这个,如何在Linux/Unix上永久设置$PATH,但我有一个错误消息说没有这样的文件和目录,所以我想我可以尝试~/。Bash_profile而不是~/。但它没有工作。

其次,我发现了这个解决方案如何设置的$PATH为使用的应用程序在os x,其中建议做改变

~/.MacOSX/environment.plist

但我没有这样的文件和目录错误。

我需要一种方法来设置这些变量,这样就不需要每次打开一个新的终端会话时都一次又一次地设置它们。


当前回答

在Mac中设置路径有两种方法。

创建一个文件的变量名和粘贴路径下 /etc/paths.D,并将该文件源到profile_bashrc。 导出~/中的路径变量。profile_bashrc作为 export VARIABLE_NAME = $(PATH_VALUE)

和源路径。它简单而稳定。

你可以在Mac终端或linux中设置任何路径变量。

其他回答

你必须把它添加到/etc/paths.

参考资料(对我有用):这里

sudo nano /etc/paths

现在找到命令路径,我给出了一个颤振路径设置的例子。

/Users/username/development/flutter/bin

现在ctrl +x,然后y。重新打开终端并检查。

你还可以加上这个

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

~ /。Bash_profile然后创建~/。bashrc,你可以添加更多的路径到PATH。一个例子。

export PATH=$PATH:.

在Mac中设置路径有两种方法。

创建一个文件的变量名和粘贴路径下 /etc/paths.D,并将该文件源到profile_bashrc。 导出~/中的路径变量。profile_bashrc作为 export VARIABLE_NAME = $(PATH_VALUE)

和源路径。它简单而稳定。

你可以在Mac终端或linux中设置任何路径变量。

我发现有一些文件可能会影响macOS中的$PATH变量(适用于我,10.11 El Capitan),列出如下:

As the top voted answer said, vi /etc/paths, which is recommended from my point of view. Also don't forget the /etc/paths.d directory, which contains files may affect the $PATH variable, set the git and mono-command path in my case. You can ls -l /etc/paths.d to list items and rm /etc/paths.d/path_you_dislike to remove items. If you're using a "bash" environment (the default Terminal.app, for example), you should check out ~/.bash_profile or ~/.bashrc. There may be not that file yet, but these two files have effects on the $PATH. If you're using a "zsh" environment (Oh-My-Zsh, for example), you should check out ~./zshrc instead of ~/.bash* thing.

不要忘记重新启动所有终端窗口,然后回显$PATH。$PATH字符串将是PATH_SET_IN_3&4:PATH_SET_IN_1:PATH_SET_IN_2。

注意,前两种方式(/etc/paths和/etc/path.d)在/目录下,这将影响您计算机中的所有帐户,而最后两种方式(~/. path.d)在/目录下。bash*或~/.zsh*)在~/目录下(也就是/Users/yourusername/),这只会影响你的帐户设置。

阅读更多:Mac OS X:设置/更改$PATH变量- nixCraft