associatesnowbot

Env File For Mac

Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI applications, your only option is /etc/launchd.conf. Please note that. Open a terminal prompt. Type sudo vi /etc/launchd.conf (note: this file might not yet exist).

Put contents like the following into the file # Set environment variables here so they are available globally to all apps # (and Terminal), including those launched via Spotlight. # # After editing this file run the following command from the terminal to update # environment variables globally without needing to reboot.

# NOTE: You will still need to restart the relevant application (including # Terminal) to pick up the changes! # grep -E '^setenv' /etc/launchd.conf xargs -t -L 1 launchctl # # See # and # # Note that you must hardcode the paths below, don't use environment variables.

# You also need to surround multiple values in quotes, see MAVENOPTS example below. # setenv JAVAVERSION 1.6 setenv JAVAHOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home setenv GROOVYHOME /Applications/Dev/groovy setenv GRAILSHOME /Applications/Dev/grails setenv NEXUSHOME /Applications/Dev/nexus/nexus-webapp setenv JRUBYHOME /Applications/Dev/jruby setenv ANTHOME /Applications/Dev/apache-ant setenv ANTOPTS -Xmx512M setenv MAVENOPTS '-Xmx1024M -XX:MaxPermSize=512m' setenv M2HOME /Applications/Dev/apache-maven setenv JMETERHOME /Applications/Dev/jakarta-jmeter. Save your changes in vi and reboot your Mac. Or use the / command which is shown in the code comment above.

Prove that your variables are working by opening a Terminal window and typing export and you should see your new variables. These will also be available in IntelliJ IDEA and other GUI applications you launch via Spotlight. How to set the environment for new processes started by Spotlight (without needing to reboot) You can set the environment used by launchd (and, by extension, anything started from Spotlight) with launchctl setenv. For example to set the path: launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin Or if you want to set up your path in.bashrc or similar, then have it mirrored in launchd: PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin launchctl setenv PATH $PATH There's no need to reboot though you will need to restart an app if you want it to pick up the changed environment. This includes any shells already running under Terminal.app, although if you're there you can set the environment more directly, e.g. With export PATH=/opt/local/bin:/opt/local/sbin:$PATH for bash or zsh.

How to keeping changes after a reboot To keep changes after a reboot you can set the environment variables from /etc/launchd.conf, like so: setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin launchd.conf is executed automatically when you reboot. If you want these changes to take effect now, you should use this command to reprocess launchctl.conf (thanks @mklement for the tip!) egrep -v '^ s.#' /etc/launchd.conf launchctl You can find out more about launchctl and how it loads launchd.conf with the command man launchctl. @MattCurtis Thanks, I appreciate the update - and thanks for reading the manual:) I was getting excited about a user-level option via /.launchd.conf, but it turns out it doesn't work as of OS X 10.8.3 (I've tried several variations) - the file is simply ignored; I've filed a bug with Apple. Also, it turns out that launchctl (as of at least OS X 10.8.3) can read commands from stdin - except that it can't deal with comment lines! Thus, the (relatively) best way to load pending changes is as follows: egrep -v '^ s.#' '/etc/launchd.conf' launchctl.

– Jun 1 '13 at 4:16. There are essentially two problems to solve when dealing with environment variables in OS X.

The first is when invoking programs from Spotlight (the magnifying glass icon on the right side of the Mac menu/status bar) and the second when invoking programs from the Dock. Invoking programs from a Terminal application/utility is trivial because it reads the environment from the standard shell locations ( /.profile, /.bashprofile, /.bashrc, etc.) When invoking programs from the Dock, use /.MacOSX/environment.plist where the element contains a sequence of KEYtheValue elements. When invoking programs from Spotlight, ensure that launchd has been setup with all the key/value settings you require. To solve both problems simultaneously, I use a login item (set via the System Preferences tool) on my User account. The login item is a bash script that invokes an Emacs lisp function although one can of course use their favorite scripting tool to accomplish the same thing. This approach has the added benefit that it works at any time and does not require a reboot, i.e.

One can edit /.profile, run the login item in some shell and have the changes visible for newly invoked programs, from either the Dock or Spotlight. Details: Login item: /bin/macosx-startup #!/bin/bash bash -l -c '/Applications/Emacs.app/Contents/MacOS/Emacs -batch -l /lib/emacs/elisp/macosx/environment-support.el -f generate-environment' Emacs lisp function: /lib/emacs/elisp/macosx/envionment-support.el;;; Provide support for the environment on Mac OS X (defun generate-environment 'Dump the current environment into the /.MacOSX/environment.plist file.' ;; The system environment is found in the global variable:;; 'initial-environment' as a list of 'KEY=VALUE' pairs. (let ((list initial-environment) pair start command key value);; clear out the current environment settings (find-file '/.MacOSX/environment.plist') (goto-char (point-min)) (setq start (search-forward ' n')) (search-forward ') (beginning-of-line) (delete-region start (point)) (while list (setq pair (split-string (car list) '=') list (cdr list)) (setq key (nth 0 pair) value (nth 1 pair)) (insert ' ' key ' n') (insert ' ' value ' n');; Enable this variable in launchd (setq command (format 'launchctl setenv%s '%s ' key value)) (shell-command command));; Save the buffer. (save-buffer))) NOTE: This solution is an amalgam of those coming before I added mine, particularly that offered by Matt Curtis, but I have deliberately tried to keep my /.bashprofile content platform independent and put the setting of the launchd environment (a Mac only facility) into a separate script.

Env File For Mac

Another, free, opensource, Mac OSX Mountain Lion (10.8) Preference pane/environment.plist solution is. EnvPane's available on. EnvPane looks like it has comparable features to, however, it seems it can update its stored variables instantly, i.e. Without the need for a restart or login, which is welcome. As stated by the developer: EnvPane is a preference pane for Mac OS X 10.8 (Mountain Lion) that lets you set environment variables for all programs in both graphical and terminal sessions. Not only does it restore support for /.MacOSX/environment.plist in Mountain Lion, it also publishes your changes to the environment immediately, without the need to log out and back in. EnvPane includes (and automatically installs) a launchd agent that runs 1) early after login and 2) whenever the /.MacOSX/environment.plist changes.

The agent reads /.MacOSX/environment.plist and exports the environment variables from that file to the current user's launchd instance via the same API that is used by launchctl setenv and launchctl unsetenv. Disclaimer: I am in no way related to the developer or his/her project. I like the name (sounds like 'Ends Pain'). On Mountain Lion all the /etc/paths and /etc/launchd.conf editing doesn't take any effect! Apple's Developer Forums say: 'Change the Info.plist of the.app itself to contain an 'LSEnvironment' dictionary with the environment variables you want. /.MacOSX/environment.plist is no longer supported.'

So I directly edited the app's Info.plist (right click on 'AppName.app' (in this case SourceTree) and then ' Show package contents') and added a new key/dict pair called: LSEnvironment PATH /Users/flori/.rvm/gems/ruby-1.9.3-p362/bin:/Users/flori/.rvm/gems/ruby-1.9.3-p362@global/bin:/Users/flori/.rvm/rubies/ruby-1.9.3-p326/bin:/Users/flori/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin: (see: ) now the App (in my case SourceTree) uses the given path and works with git 1.9.3:-) PS: Of course you have to adjust the Path entry to your specific path needs. While the answers here aren't 'wrong', I'll add another: never make environment variable changes in OS X that affect 'all processes', or even, outside the shell, for all processes run interactively by a given user. In my experience, global changes to environment variables like PATH for all processes are even more likely to break things on OS X than on Windows.

Reason being, lots of OS X applications and other software (including, perhaps especially, components of the OS itself) rely on UNIX command-line tools under the hood, and assume the behavior of the versions of these tools provided with the system, and don't necessarily use absolute paths when doing so (similar comments apply to dynamically-loaded libraries and DYLD. environment variables).

Consider, for instance, that the highest-rated answers to various Stack Overflow questions about replacing OS X-supplied versions of interpreters like Python and Ruby generally say 'don't do this.' OS X is really no different than other UNIX-like operating systems (e.g., Linux, FreeBSD, and Solaris) in this respect; the most likely reason Apple doesn't provide an easy way to do this is because it breaks things. To the extent Windows isn't as prone to these problems, it's due to two things: (1) Windows software doesn't tend to rely on command-line tools to the extent that UNIX software does, and (2) Microsoft has had such an extensive history of both 'DLL hell' and security problems caused by changes that affect all processes that they've changed the behavior of dynamic loading in newer Windows versions to limit the impact of 'global' configuration options like PATH.

'Lame' or not, you'll have a far more stable system if you restrict such changes to smaller scopes. Sometimes all of the previous answers simply don't work. If you want to have access to a system variable (like M2HOME) in Eclipse or in IntelliJ IDEA the only thing that works for me in this case is: First (step 1) edit /etc/launchd.conf to contain a line like this: 'setenv VAR value' and then (step 2) reboot. Simply modifying.bashprofile won't work because in OS X the applications are not started as in other Unix'es; they don't inherit the parent's shell variables. All the other modifications won't work for a reason that is unknown to me. Maybe someone else can clarify about this.

What are Environment Variables? Environment variables are global system variables accessible by all the processes running under the Operating System (OS). Environment variables are useful to store system-wide values such as the directories to search for the executable programs ( PATH) and the OS version.

Examples of environment variables in Windows OS are:. COMPUTENAME, USERNAME: stores the computer and current user name. OS: the operating system. SystemRoot: the system root directory. PATH: stores a list of directories for searching executable programs.

In setting up JDK and Java applications, you will encounter these environment variables: PATH, CLASSPATH, JAVAHOME and JREHOME. In short:. PATH: maintains a list of directories. The OS searches the PATH entries for executable programs, such as Java Compiler ( javac) and Java Runtime ( java).

Env File For Mac Os

CLASSPATH: maintain a list of directories (containing many Java class files) and JAR file (a single-file archive of Java classes). The Java Compiler and Java Runtime searches the CLASSPATH entries for Java classes referenced in your program. JAVAHOME and JREHOME: maintain the locations of JDK and JRE installed directory, respectively. (Windows) How to Set or Change an Environment Variable Variables in Windows are NOT case-sensitive (because the legacy DOS is not case-sensitive).

Env File For Macro

Environment variables are typically named in uppercase, with words joined with underscore ( ), e.g., JAVAHOME. Display Variables and their Values To list all the variables and their values, start a CMD shell (Click 'Start' button ⇒ Run ⇒ Enter 'cmd') and issue the command ' set'. To display a particular variable, use command ' set varname'. For examples, // Display all the variables (in NAME=VALUE pairs) prompt set COMPUTERNAME=xxxxxxx OS=xxxxxxx PATH=xxxxxxx. // Display a particular variable prompt set COMPUTERNAME COMPUTERNAME=xxxxxx // OR use echo command with variable enclosed within a pair of '%'s prompt echo%COMPUTERNAME% COMPUTERNAME=xxxxxx Try issuing a set command on your system, and study the environment variables listed.

Pay particular attention to the variable called PATH. Set/Change/Unset a Variable To set (or change) a variable, use command ' set varname= value'.

There shall be no spaces before and after the '=' sign. To unset an environment variable, use ' set varname=', i.e., set it to an empty string.