7

My ~/etc/path looks as follows:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

The Problem:

When I type echo $PATH into terminal, I get back:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

And this persists for every application started in the terminal. For instance, if I type emacs, and then do:

M-x getenv PATH

My output is:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

However, if I start up emacs using launchpad instead of terminal and once again enter M-x getenv PATH, my output is instead /usr/bin:/bin:/usr/sbin:/sbin.

As you can see my change to ~/etc/path, which was the addition of /usr/local/bin, is missing.

Another Example:

I use a Firefox plugin called vimperator which emulates vim functionality in Firefox. It has a feature that allows the user to edit webpage input in vim. However, this does not seem to work on OS X. On a hunch I type the command !echo $PATH into vimperator and see the following: /usr/bin:/bin:/usr/sbin:/sbin. Of course, since the symlink called gvim, which points to macvim, was created and placed into /usr/local/bin by brew, this behavior makes sense. What I don't understand is why the PATH is read the way it is.

Solutions that I have tried:

  • I have obviously restarted my machine.

EDIT (As requested by now deleted comment):

using sysctl user.cs_path in the terminal brings up:

user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin
  • @fd0 Sure. I'm done, and this is the exact path that I have been getting. – FabulousGlobe Jun 20 '16 at 21:21
8

The loginwindow process sets a user's environment. It sets the variables TMPDIR and PATH, consults Directory Services and sets SHELL HOME USER LOGNAME . PATH is set to /usr/bin:/bin:/usr/sbin:/sbin unless modified by launchd (in the more current versions of OS X). This is the PATH variable available to the user's processes unless modified by that particular process (cron as an example sets the PATH to /bin:/usr/bin).

Terminal emulator applications start your shell as a login shell thus the PATH is modified by reading the various shell startup file. Any process started by your shell now inherits the new PATH variable. Other applications using a shell do not read any shell config files and use those environment variables available in the current environment. An application may modify the environment by using the LSEnvironment key in their Info.plist.

As of Yosemite, you can change the PATH variable in the following form.

sudo launchctl config user path <path>

in your case you want /usr/local/bin at the front of the path.

sudo launchctl config user path /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

reboot your system and the new PATH will be set by loginwindow.

-1

Run this:

launchctl setenv PATH "$PATH"

EDIT: That no longer works. Use this with Bash instead:

CURRENT="$(/usr/libexec/PlistBuddy -c "Print PATH" ~/.MacOSX/environment.plist)"
/usr/libexec/PlistBuddy -c "Set PATH $CURRENT:/your/path/here:/another/path/maybe" ~/.MacOSX/environment.plist

Then log out and log in again.

Note: You may want to replace $CURRENT:/your/path/here:/another/path/maybe with just a list of paths like :/your/path/here:/another/path/maybe, but that is a bad idea becase it will erase all paths already stored.

This uses User Session Environment Variables.

  • I tried both simply running the command, as well as adding it to both my .profile and .bash_profile. The PATH is still set to /usr/bin:/bin:/usr/sbin:/sbin in Eclipse, Vimperator (firefox), and Emacs. The strange thing is, if I use the option to execute a shell script in either Emacs or Vimperator, running echo $PATH gets me /usr/bin:/bin:/usr/sbin:/sbin. However, running launchctl getenv PATH produces /usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin; I don't know how to execute a shell script in Eclipse. I restarted after I made the changes to my dot files of course. – FabulousGlobe Jun 20 '16 at 20:45
  • This is also what is displayed if I type echo $PATH in the terminal. – FabulousGlobe Jun 20 '16 at 20:50
  • 1
    What exactly is that command supposed to do? – Allan Jun 20 '16 at 20:51
  • @Allan I did come across that command as well while googling for answers. Apparently it used to set environmental variables back in 10.8. Now it doesn't work. – FabulousGlobe Jun 20 '16 at 21:05
  • The command was supposed to notify launchctl about the new PATH variable, but apparently that doesn't work anymore. I updated my answer with a new solution. – Coder-256 Jun 21 '16 at 14:40

You must log in to answer this question.

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