From what I have gleaned in various places with discussions about /usr/libexec/path_helper and all, apparently the modern way to add items to the environment variable PATH in macOS Sierra 10.12 is to either:

  • Edit the /etc/paths file
  • Add file(s) to be read from the /etc/paths.d directory.

My Questions:

  • Which is more kosher on modern macOS?
  • If the better or more common way is dropping files into the paths.d directory, what should be the names and content of those files? Any examples?
  • I am using zsh rather than bash. Does that make a difference?
  • Are these two options unique to macOS? Or do they appear in BSD or other Unix-like systems?
  • Still waiting for an answer for the last bullet
    – Steven Lu
    Oct 31 at 1:27

Use /etc/paths.d. The primary reason is that /etc/paths will be modified and/or replaced by system upgrades. /etc/paths.d/ items will not. Files are generally named with the pattern index-source. E.g., 99-mypaths. Paths are appended in order*. It's a lot easier to simply add/remove a file than programmatically editing one idempotently without bugs.

The default csh.login, profile, and zprofile on macOS all load path_helper.

* Probably ASCII order, but maybe LOCALE order.

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.