Matthew Price

Zsh PATH Issues in OS X 10.11, El Capitan

I immediately ran into problems with my PATH after upgrading to El Capitan. Instead of using my custom version of Ruby, El Capitan was using the system version. It was easy to spot why: OS X was reordering $PATH.

If you’re having the same problem, I suspect we have similar setups: I set $PATH in ~/.zshenv so Pow and GoSublime have access to it; I configure aliases and functions in ~/.zshrc since it’s more efficient to only load them for interactive sessions.

As it happens, El Capitan introduced a global Zsh profile at /etc/zprofile that calls /usr/libexec/path_helper, a utility which adds system directories to $PATH, reorders it, and then removes duplicates.1 Our customizations are being overwritten because Zsh calls /etc/zprofile after ~/.zshenv.

Solution 1: Disable Loading Global Profiles

If you don’t want to load /etc/zprofile or other global settings, there’s a command to disable them. All you do is add this line somewhere in your ~/.zshenv file:

setopt no_global_rcs

There are two things to be aware of with this fix although I find it highly unlike either will affect you:

  1. Future OS versions may modify these files with changes you need.
  2. If you’re on a multiuser system, your system administrator could be using the global files to configure settings and functions related to your job.

Since I find it unlikely OS X will change these files and since I am my own system administrator, this is the solution I’ve personally enacted.

Solution 2: Don’t Set $PATH in Zshenv

The biggest reason I set my PATH in zshenv is so Pow and GoSublime will have access to it, but most programs have multiple ways to set their search locations. For instance, Pow checks ~/.powconfig for exported variables. Likewise, GoSublime has a settings file where you can set $PATH and $GOPATH. Just move your PATH setup to ~/.zshrc or ~/.zprofile and configure your tools using their custom methods.

For instance, a Pow config for use with rbenv might look like this:

export PATH=/Users/$(whoami)/.rbenv/shims:$PATH

The downside is you will need to update multiple files if you ever change your Ruby, Go, or similar setup.

  1. OS X has always done this for Bash (in /etc/profile) and Csh (in /etc/csh.login). While an annoying change, it appears to have been made for consistency.