Environment variables in Mac OS X

environment-variables, macos

Solution

There's no need for duplication. You can set environment variables used by launchd (and child processes, i.e. anything you start from Spotlight) using `launchctl setenv`.

For example, if you want to mirror your current path in launchd after setting it up in `.bashrc` or wherever:

PATH=whatever:you:want
launchctl setenv PATH $PATH

Environment variables are not automatically updated in running applications. You will need to relaunch applications to get the updated environment variables (although you can just set variables in your shell, e.g. `PATH=whatever:you:want`; there's no need to relaunch the terminal).

Problem

Update: The link below does not have a complete answer. Having to set the path or variable in two places (one for GUI and one for shell) is lame. Not Duplicate of: Setting environment variables in OS X? Coming from a Windows background where it's very easy to set and modify environment variables (just go to System Properties > Advanced > Environment Variables), it does not seem to be that straight forward on Mac OS 10.5. Most references say I should update /etc/profile or ~/.profile. Are those the equivalent of System Variables and User Variables? For example, where should I set my `JAVA_HOME` variable? EDIT: I want to be able to access the variable from the terminal as well as an app like Eclipse. Also, I hope I don't have to restart/logout to make this take effect.

Original source

Related problems