Environment variables can be used to specify configuration information to software.
An environment variable can be set temporarily in a single shell, and will only affect applications launched from that shell. Once the shell is closed (e.g. on a logout or reboot) the environment variable is removed.
From a “cmd.exe” shell, use the 'set' command:
The syntax varies depending on the shell you're using. First, open a Terminal window, then if using bash (default on Linux and Mac OS X) type:
NAME=VALUE; export NAME
or if using csh or tcsh:
setenv NAME VALUE
If you wish to retain an environment variable across shells and reboots etc., use this method:
First, open the “Environment variables” editor. Its location is a little bit hidden.
On the left hand side of the window, you will see the environment variable name, and on the right hand side the variables value. Variables can be set either just for the current user or system-wide for all users.
1. Environment variables can be set from a Terminal window. 2. From a terminal window, type the following lines, replacing “NAME” with the environment variable name and “VALUE” with its value:
echo "NAME=VALUE; export NAME" >> ~/.profile echo "setenv NAME VALUE" >> ~/.cshrc defaults write ~/.MacOSX/environment NAME -string "VALUE"; plutil -convert xml1 ~/.MacOSX/environment.plist
The first line sets the environment for users with users with sh or bash as their shell, the second for users with csh or tcsh as their shell, and the third for programs launched by the Finder (including Xcode).
Last modified: 2015/06/05 10:25 (external edit)