Where to place $ PATH variables in zsh?

I like zsh , but I'm not sure where to put my $PATH statements and other variables? I found that they are scattered between .zshrc .zprofile .bashrc .bash_profile files, and sometimes double.

I understand that having something inside bash files does not make much sense since I am using zsh , but where exactly should I put my rvm , python , node , etc. to my $PATH ?

Is there a specific file that I should use (i.e. .zshenv , which currently does not exist in my installation), one of the ones that I am currently using, or does it even matter?

+74
shell zsh macos
May 13 '12 at 19:48
source share
3 answers

tl; dr version: use ~/.zshrc

And read the man page to understand the differences between the two:

~/.zshrc , ~/.zshenv and ~/.zprofile .




Regarding my comment

In my comment on the answer kev gave , I said:

This seems wrong - / etc / profile is not listed in any zsh documentation I can find.

This turns out to be partially wrong: /etc/profile can be obtained using zsh . However , this only happens if zsh "is invoked as sh or ksh "; in these compatibility modes:

Normal zsh startup / shutdown scripts are not executed. Enter the shell source code / etc / profile followed by $ HOME / .profile. If the ENV environment variable is set during the call, $ ENV is obtained after the profile scripts. ENV is subject to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a path. [ man zshall, "Compatibility" ].

ArcWiki ZSH Link says:

When logged in, Zsh sends the following files in the following order:
/ Etc / profile | This file is created by all Bourne-compatible shells upon login.

This means that /etc/profile always read by zsh at login - I have no experience with an Arch Linux project; Wikis may be correct for this distribution, but this is usually not the case. Information incorrect compared to zsh man pages and doesnโ€™t seem to apply to zsh on OS X (the paths in $PATH set in /etc/profile do not fall into my zsh sessions)





To ask a question:

where exactly should I host my rvm, python, node, etc. additions to my $ PATH?

Normally, I would export my $PATH from ~/.zshrc , but itโ€™s worth reading the zshall man page, in particular, the section "STARTUP / SHUTDOWN FILES" - ~/.zshrc is read for interactive shells that may or may not suit your needs - if you want $PATH for every zsh shell you zsh (both interactive and not both login and no, etc.) then ~/.zshenv is the best option.

Is there a specific file that I should use (e.g. .zshenv, which currently does not exist in my installation), one of the ones that I am currently using, or does it even matter?

There is a bunch of files read at startup (check the related man pages), and there is a reason for this: each file has its own special place (settings for each user, settings for user settings for login systems, settings for each shell, etc. d.).
Don't worry about ~/.zshenv not existing - if you need it, do it and it will be read.

.bashrc and .bash_profile are not considered read by zsh unless you explicitly use them from ~/.zshrc or the like; The syntax between bash and zsh not always compatible. Both .bashrc and .bash_profile are for bash settings, not zsh .

+96
May 14 '12 at 12:27
source share

Here are the documents from the zsh manual pages in the STARTUP / SHUTDOWN FILES section.

  Commands are first read from /etc/zshenv this cannot be overridden. Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the former affects all startup files, while the second only affects global startup files (those shown here with an path starting with a /). If one of the options is unset at any point, any subsequent startup file(s) of the corresponding type will not be read. It is also possi- ble for a file in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and GLOBAL_RCS are set by default. Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zpro- file. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read. 

From this one can see that the order files are read:

 /etc/zshenv # Read for every shell ~/.zshenv # Read for every shell except ones started with -f /etc/zprofile # Global config for login shells, read before zshrc ~/.zprofile # User config for login shells /etc/zshrc # Global config for interactive shells ~/.zshrc # User config for interactive shells /etc/zlogin # Global config for login shells, read after zshrc ~/.zlogin # User config for login shells ~/.zlogout # User config for login shells, read upon logout /etc/zlogout # Global config for login shells, read after user logout file 

You can get more information here .

+19
Jan 02 '15 at 13:01
source share

I had a similar problem (in bash, the terminal command worked correctly, but zsh showed the command not found error)

Decision:


just paste everything that you insert into ~ / .bashrc earlier to:

 ~/.zshrc 
+8
Mar 22 '15 at 4:36
source share



All Articles