在这里似乎有一百个关于如何在Mac OS X / Linux环境中改变你的路径的问题....事实上,我认为实际上知道如何改变我的PATH变量,但似乎有些东西导致它被覆盖我正在使用zsh并尝试让Brew Doctor
不要警告我在user / local / bin之前使用usr / bin。
我的〜/ .zprofile:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
echo $PATH
登录后我得到:
Last login: Fri Oct 17 15:10:30 on ttys000
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
但是在登录后运行$ PATH我得到:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
我正在直接登录到zsh但是以防我的.profile和.bash-profile都包含与我的.zprofile相同的代码,而我的/etc/paths.d目录中没有任何内容。是否有其他地方设置了PATH?我在这里缺少什么?
答案 0 :(得分:8)
自: https://wiki.archlinux.org/index.php/zsh
用户应注意/ etc / profile设置$ PATH变量 覆盖〜/ .zshenv中设置的任何$ PATH变量。为防止这种情况,请设置 〜/ .zshrc中的$ PATH变量。 (不建议更换默认值 / etc / zsh / zprofile中的一行包含其他内容,它会破坏完整性 在/etc/profile.d中提供一些脚本的其他软件包。)
自: http://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/
For zsh: [Note that zsh seems to read ~/.profile as well, if ~/.zshrc is not present.]
+----------------+-----------+-----------+------+
| |Interactive|Interactive|Script|
| |login |non-login | |
+----------------+-----------+-----------+------+
|/etc/zshenv | A | A | A |
+----------------+-----------+-----------+------+
|~/.zshenv | B | B | B |
+----------------+-----------+-----------+------+
|/etc/zprofile | C | | |
+----------------+-----------+-----------+------+
|~/.zprofile | D | | |
+----------------+-----------+-----------+------+
|/etc/zshrc | E | C | |
+----------------+-----------+-----------+------+
|~/.zshrc | F | D | |
+----------------+-----------+-----------+------+
|/etc/zlogin | G | | |
+----------------+-----------+-----------+------+
|~/.zlogin | H | | |
+----------------+-----------+-----------+------+
| | | | |
+----------------+-----------+-----------+------+
| | | | |
+----------------+-----------+-----------+------+
|~/.zlogout | I | | |
+----------------+-----------+-----------+------+
|/etc/zlogout | J | | |
+----------------+-----------+-----------+------+
Moral:
For bash, put stuff in ~/.bashrc, and make ~/.bash_profile source it.
For zsh, put stuff in ~/.zshrc, which is always executed.
答案 1 :(得分:3)
在读取.zprofile之后,zsh将读取.zshrc和.zlogin(假设登录shell)。您的PATH可能会被重置。
通常,PATH最好设置在.zshenv中(即使shell不是登录shell也会被读取)。然后不要在任何其他启动文件中设置它。
答案 2 :(得分:0)
如果您使用的是Jet Brains产品(pycharm / goland / webstorm等),您可能会发现其终端上的JB Shell集成正在覆盖$PATH
。您可以通过取消勾选来禁用它
设置>工具>终端> Shell集成。
有关更多信息,请参见https://www.jetbrains.com/help/pycharm/settings-tools-terminal.html。