![]() Now, load the launch agent for current session: launchctl load ~/Library/LaunchAgents/ist Make sure the shell script is executable: chmod x ~/.osx-env-sync.sh Create it at ~/.osx-env-sync.sh with the following contents: grep export $HOME/.bash_profile | while IFS=' =' read ignoreexport envvar ignorevalue do l parameter is critical here it's necessary for executing the shell script with a login shell so that ~/.bash_profile is sourced in the first place before this script is executed. named ist) in ~/Library/LaunchAgents/ directory with the following contents: We'll also need a shell script to parse these definitions and build necessary commands to be executed by the agent.Ĭreate a file with plist suffix (e.g. We need a Launch Agent which will run on each login and anytime on demand which is going to load these variables to the user session. Let's assume you have environment variable definitions in your ~/.bash_profile like in the following snippet: export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"Įxport PATH="$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin"Įxport PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"Įxport MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH" Solution for both command line and GUI applications from a single source (works with Mac OS X v10.10 (Yosemite) and Mac OS X v10.11 (El Capitan)) You can find out more about launchctl and how it loads nf with the command man launchctl. ![]() If you want these changes to take effect now, you should use this command to reprocess nf (thanks for the tip!) egrep -v '^\s*#' /etc/nf | launchctl nf is executed automatically when you reboot. To keep changes after a reboot you can set the environment variables from /etc/nf, like so: setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin The launchctl man page quote at the top of this answer says the feature described here (reading /etc/nf at boot) was removed for security reasons, so ymmv. Use launchctl config user path /bin:/usr/bin:/mystuff. How to keeping changes after a reboot New method (since 10.10 Yosemite) with export PATH=/opt/local/bin:/opt/local/sbin:$PATH for bash or zsh. This includes any shells already running under Terminal.app, although if you're there you can set the environment more directly, e.g. There's no need to reboot though you will need to restart an app if you want it to pick up the changed environment. bashrc or similar, then have it mirrored in launchd: PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin For example to set the path: launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin You can set the environment used by launchd (and, by extension, anything started from Spotlight) with launchctl setenv. How to set the environment for new processes started by Spotlight (without needing to reboot) While it was documented that $HOME/.nf would be consulted prior to setting up a user's session, this functionality was never implemented. The /etc/nf file is no longer consulted for subcommands to run during early boot time this functionality was removed for security considerations. Launchctl no longer has an interactive mode, nor does it accept commands from stdin. The man page for launchctl says that it never worked: These will also be available in IntelliJ IDEA and other GUI applications you launch via Spotlight. Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. Or use the grep/ xargs command which is shown in the code comment above. Save your changes in vi and reboot your Mac. Setenv JMETER_HOME /Applications/Dev/jakarta-jmeter Setenv M2_HOME /Applications/Dev/apache-maven Setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m" Setenv ANT_HOME /Applications/Dev/apache-ant Setenv JRUBY_HOME /Applications/Dev/jruby Setenv NEXUS_HOME /Applications/Dev/nexus/nexus-webapp Setenv GRAILS_HOME /Applications/Dev/grails Setenv GROOVY_HOME /Applications/Dev/groovy Setenv JAVA_HOME /System/Library/Frameworks/amework/Versions/1.6/Home # You also need to surround multiple values in quotes, see MAVEN_OPTS example below. # Note that you must hardcode the paths below, don't use environment variables. ![]() # grep -E "^setenv" /etc/nf | xargs -t -L 1 launchctl # NOTE: You will still need to restart the relevant application (including # environment variables globally without needing to reboot. # After editing this file run the following command from the terminal to update # (and Terminal), including those launched via Spotlight. ![]() Put contents like the following into the file # Set environment variables here so they are available globally to all apps Type sudo vi /etc/nf (note: this file might not yet exist) Please note that ist does not work for applications launched via Spotlight. I've done extensive research and if you want to set variables that are available in all GUI applications, your only option is /etc/nf.
0 Comments
Leave a Reply. |