According to the docs

.zshenv is sourced on all invocations of the shell, unless the -f option is set. It should contain commands to set the command search path, plus other important environment variables. .zshenv should not contain commands that produce output or assume the shell is attached to a tty.

Okay, cool, so I would assume that logging in via ssh is considered an invocation of zsh... but maybe not?

wayne@arglefraster ~ 
⚘ echo $PATH                                                                                                   10:01:17
wayne@arglefraster ~ 
⚘ zsh                                                                                                          10:01:20
wayne@arglefraster ~ 
⚘ echo $PATH                                                                                                   10:01:24

Those extra bits of path are added in my .zshenv file.

Is this normal, or do I have something wonky going on? Should I move my PATH modifications elsewhere?

  • You have zsh as your default shell in /etc/passd or you start it somehow different? – Jakuje Mar 25 '16 at 15:35
  • @Jakuje almost added this to the question: wayne:x:1000:100::/home/wayne:/bin/zsh – Wayne Werner Mar 25 '16 at 15:37
  • Use zsh -o SOURCE_TRACE to confirm what files are being read, and then zsh -x to see what configuration is done, in particular for PATH, in the event something else is trampling the .zshenv changes. – thrig Mar 25 '16 at 15:57

zshenv is indeed read by every instance of the shell, but it is read first, before anything else. Your $PATH is probably getting reset in zprofile (~/.zprofile or /etc/zprofile, ...).

zshenv is not a good place to set your $PATH. It belongs in zprofile, which has the job of setting up the environment upon login. Setting environment variables in zshenv means among other things that they will get clobbered when running simple zsh subshells or zsh scripts within one session.

  • Well, it definitely wasn't getting reset in ~/.zprofile or /etc/zprofile, as I have neither of those files. Nor ~/.zshrc, as there's no PATH variable there. But, setting the PATH in ~/.zprofile does appear to work properly. Following @thrig's comment, it may have been the virtualenvwrapper, though it seems strange that it would totally clobber the PATH – Wayne Werner Mar 28 '16 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.