PATH variable in .zshenv or .zshrc

纵饮孤独 提交于 2021-02-07 05:15:15

问题


My setup is zsh 5.0.5 in arch linux

I have set the PATH variable as below in .zshenv

typeset -U path
path=(~/bin $path)
DW=$HOME/Downloads

but it didn't work. print $PATH shows only

/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl

.zshenv was read, because I could see DW variable is set. Only PATH variable isn't set. And what I don't understand is, after rename the .zshenv to .zshrc, PATH variable just works as intended.

Need any special treatment setting environment variables in .zshenv?


回答1:


I just encountered this problem myself, and the real answer is that Zsh on Arch sources /etc/profile – which overwrites and exports PATHafter having sourced ~/.zshenv.

See: https://wiki.archlinux.org/index.php/Zsh#Configuration_files




回答2:


It seems that when you have macos or some linux distros there is a canonical solution to the problem which involves /etc/paths or /etc/paths.d. You should be letting /usr/libexec/path_helper construct your path for you using configuration files.

This immediately solved the problem in all places for me.




回答3:


I've got the same problem. The cause was my .zshrc (fresh install of oh-my-zsh) override PATH (ignoring existing value):

export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl"

To fix, I comment the line.



来源:https://stackoverflow.com/questions/21038903/path-variable-in-zshenv-or-zshrc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!