What is the recommended and most compatible way to set the PATH and other environment variables globally? I would like:
- A method that works from Yosemite and later versions of the OS
- It should work for both GUI + command line applications.
- It should work for both local shell and also remote SSH shells
- It should work with System Integrity Protection enabled
Here's some of the things I've tried:
- Setting the variables in ~/.bash_profile - this only seems to apply to command line apps.
- Editing /etc/paths and /etc/paths.d/ - this only seems to apply to command line apps.
- It seems possible to set some environment variables globally using launchctl and a plist. E.g.
Create file: /Library/LaunchAgents/myvars.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
And load with: launchctl load /Library/LaunchAgents/myvars.plist
This seems to work ok for environment variables other than PATH, for GUI and local shells, but not ssh. It has one other slight issue, in that it doesn't seem to work for applications that are reopened at login, if "Reopen windows when logging back in" is checked
- The "launchctl config" command seems to allow PATH to be set (after a reboot) for GUI apps, but it doesn't appear to work for the terminal. E.g:
sudo launchctl config user path /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/me/mydir
Any other others?