I have the following in my notes from some research that I did in Zsh in OS X in the past.

Between ~/.zshenv and ~/.zshrc, OSX seems to call /etc/.zprofile which calls path_helper, which itself recreates PATH using /etc/paths and /etc/paths.d

The above seems to suggest that if I want to use my own PATH for non-interative Zsh shells, I should not make those modifications in .zshenv.

This is odd, because those paths above (/etc/.zprofile /etc/paths and /etc/paths.d) are not user files and they reset PATH

  1. What exact dot files does Zsh load in OS X?
  2. What's the role of those path locations (e.g. /etc/paths and /etc/paths.d), and are they unique to OSX?
  3. What's the recommended practice for setting up PATH for a shell like in Zsh in OSX?
  • 2
    I think the most straightforward way (and the one I'm using) is putting all the environment variables in .zshenv and sudo rm /etc/zprofile.
    – noibe
    Jun 18 '20 at 12:33
  1. The same as any other Zsh installation: http://zsh.sourceforge.net/Doc/Release/Files.html#Startup_002fShutdown-Files
  2. Those are unique to macOS and are used by /etc/zprofile to populate your $path/$PATH.
  3. You don't really need to do anything by default on macOS. Everything $path-related is already set up by /etc/zprofile. If you do have additional dirs you need to add to your $path, then I recommend adding something like this to your ~/.zshrc file:
    typeset -U PATH path
    This puts my specific dirs before the rest of $path, making sure they get searched first and -U ensures that $path doesn't have any duplicate entries.
  • Thanks - in answer #2 you said: "those are unique to macOS" and then in #1 "[In macOS, Zsh uses] the same [dot files] as any other Zsh installation". By dot files I was referring more holistically to configuration files (even if granted the macOS path /etc/paths.d does not start with '.' per se). Are there any other configuration files that macOS loads when it starts Zsh that are unique to macOS? Jun 18 '20 at 16:26
  • 1
    By default, macOS comes packaged with these three Zsh dotfiles in /etc/: zprofile, zshrc and zshrc_Apple_Terminal. That last one is unique to macOS, but is in no way special; it's not loaded automatically by Zsh, but simply sourced from /etc/zshrc. /etc/paths & /etc/paths.d/ are used by /usr/libexec/path_helper to set your $PATH, which is called from /etc/zprofile. path_helper is unique to macOS, but not specific to Zsh; it simply generates paths for C shells & Bourne shells. Jun 21 '20 at 16:44

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.