Setting Environment Variables
As a Software Engineer you will eventually have to set environment variables to use some tool or library properly, yet it amazes me how few people actually know how to do this. Below are quick steps for setting environment varialbes in both Windows 7 and Linux.
Windows 7
- Click Start, Right Click My Computer, Select Properties
- In the System window click on Advanced system settings in the left pane
- In the System Properties window select Advanced tab and click on Environment Variables… button given at the bottom of the window
- In the Environment Variables window you will notice two columns User variables for a username and System variables
- To add a new User variable click on New… button. In the New User Variable dialog box type the Variable name and Variable value and click OK button
- To remove a User variable click on the required User variable and then click on Delete button
- To edit a User variable click on Edit… button. In the Edit User Variable dialog box edit the Variable name and Variable value and click OK button
- If Editing the PATH Variable, Seperate multiple entries with a semi-colon ";". You can reference other variables using the following format "%VAR_NAME%".
- Click OK button in the Environment Variables dialog window
- Click OK on System Properties window
- Close System window
- Close then reopen any command propmts you have open in order for the changes to take effect
Linux
In linux you can set environment variables temporarily, so they only exist within your shell session, or permanently, so they stay set.
Setting Environment Variables Temporarily
- Open a Terminal Window
- Execute the following command:
export VAR_NAME=VALUE
Setting Environment Variables Permanently
- Open a Terminal Window
- Execute the following command:
vi ~/.bash_proflle
- Append the following to the end of the file:
export VAR_NAME=VALUE
- If Editing the PATH Variable, Seperate multiple entries with a colon ":". You can reference other variables using the following format "{VAR_NAME}".
- Save & Close the file
- Execute the following command:
source ~/.bash_proflle
- you will need to execute this command in all open terminal windows, or logoff completly then log back in, for changes to take effect
Note: To set System Wide environment varialbes, use the same steps as above, but modify the file "/etc/profile".