3

There are other questions and topics just like this but I can not find anything that is specific to 10.14 Mojave. I have tried the ~/Library/LaunchAgents/environment.plist method and I have tried to move the same file to /Library/LaunchDaemons (and restarted) but it does not affect Emacs when it is launched from the dock, Spotlight, or the Applications window.

In that file, I did launchctl setenv PATH $PATH:/usr/local/bin Curiously, when Terminal (bash) is launched and echo $PATH > /tmp/bash.debug is the first line in ~/.bash_profile, the output is /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin so... something has prepended /usr/local/bin while I was attempting to append it.

I have not tried things like /etc/launchd.conf or ~/.MacOSX/environment.plist because the pages I find say that both of those stopped working a while back.

In particular, I want to add /usr/local/bin to PATH. Currently, my work around is to do it in my Emacs start up files.

There was one person who mentioned that setting system wide environment variables in MacOS is a bad idea and I'm tempted to go along with that. The Emacs specific solution I have works and doesn't have any side effects. But, I'd like to know how to do it ... if it is possible. Once I get curious about something its hard for me to let it go.

As always, thank you very much for your time.

  • See this thread: emacs.stackexchange.com/questions/10722/… look for user4669748' article – historystamp Dec 12 '18 at 19:16
  • 1
    @historystamp you should give the link direct to the answer emacs.stackexchange.com/a/20425/9874 – Mark Dec 13 '18 at 12:32
  • 1
    @historystamp That does not work for me. If I do: ps -Eef | grep '/Finder ' | grep -v grep | tr ' ' '\n' | grep '^PATH=' I get the output of PATH=/usr/bin:/bin:/usr/sbin:/sbin . That is getting the environment that the Finder has set. I'm assuming that the Finder is what launches applications. – pedz Dec 13 '18 at 17:43
  • I have "EmacsForMacOS" and it uses a Ruby script to start up. Perhaps that is causing the issue. I will investigate this. – pedz Dec 13 '18 at 17:53
  • I thought perhaps ruby was altering the environment before entering the script that is passed to it but from my testing that is not the case. Currently, no matter what I do, PATH is set to /usr/bin:/bin:/usr/sbin:/sbin when Emacs is spawned from the Finder. – pedz Jan 8 at 17:24
2

The answer to this one in Mojave is to create a named file in /etc/paths.d, for instance

vi /etc/paths.d/local_bin

Put

/usr/local/bin

in the file, save and quit. Start another terminal window and it will be on your path.

I have one for MacPorts

$ cat MacPorts 
/opt/local/bin
  • 1
    Thank you for helping but it appears from my testing that adding entries like you suggest is the same as adding lines to /etc/paths ... its curious that they have both. Adding lines takes affect immediately for new bash shells but processes spawned by Finder (the GUI) still has PATH=/usr/bin:/bin:/usr/sbin:/sbin ... – pedz Jan 8 at 17:23
  • In case it may be helpful to others, I had errors with permissions in the /etc/paths.d folder. I got around it by duplicating an existing file from etc/paths.d, renamed it, and moved it outside the folder (to avoid permissions trouble), replaced its content with the paths I wanted to add, then finally moved it to the /etc/paths.d folder. Good luck. – Samer s Salib Mar 4 at 18:23
  • @pedz: "its curious that they have both." – /etc/paths.d/* makes it much easier for machines to add/remove paths. It is easier for a machine to create and delete files than to figure out how to edit them. – Jörg W Mittag Apr 28 at 22:39

You must log in to answer this question.

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