22

I'm running zsh 5.1.1 on Ubuntu 16.04. It seems that ~/.zprofile isn't sourced at login nor new terminal. ~/.zshrc is sourced however.

I am running oh-my-zsh.

Any ideas on why this is or how I can fix it?

2 Answers 2

36

~/.zprofile is only sourced when zsh is run as login shell, e.g. when logging in on the console or via SSH.

It will not be sourced by zsh when opening a new terminal or starting a new zsh session from within a running session. Anything you need in all interactive sessions, should be set in ~/.zshrc. Anything you need in all zsh sessions, including scripts, should be set in ~/.zshenv.

You can find additional information in the zshall manpage and on this site.

~/.zshprofile will (usually) also not be parsed by any other tools. So any environment variables set in ~/.zprofile will usually not be available in an X11 session. If you need some environment variable to be available globally in your session, you might want to have a look at man pam_env.

4
  • What if login operation is done via ssh authorized key, zsh will still detected as login shell?
    – alper
    Aug 11, 2021 at 22:09
  • @alper that depends on the login shell set for the user in the system and has nothing to do with the ssh connection
    – xeruf
    Dec 14, 2021 at 18:23
  • debian 12 . ~/.config/zsh/.zprofile is sourced when opening alacrity with zsh as the shell.
    – RichieHH
    Nov 23, 2023 at 19:13
  • 1
    @RichieHH Unfortunately I don't have a Debian at hand to dig into this, but at least the manpage provided with the zsh-common package on Debian still states that $ZDOTDIR/.zprofile is only read for login shells. There might something else going: alacritty might explicitly call zsh as login shell (zsh -l). Alternatively, ~/.config/zsh/.zprofile might be sourced by some other like ~/.zshenv or $ZDOTDIR/.zshrc. Are you perchance using some pre-made configuration like github.com/getantidote/zdotdir (which explicitly loads .zprofile from .zshenv for non-login shells)?
    – Adaephon
    Dec 1, 2023 at 10:26
3

I had the same issue and found out that while ~/.zprofile seems to be ignored, ~/.profile still gets sourced. Not sure why this is the case, but simply moving things from .zprofile to .profile solved the problem for me...

1
  • 2
    Same for me on MacOS 14.0
    – Jason Dark
    Oct 8, 2023 at 20:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .