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

  1. Click Start, Right Click My Computer, Select Properties
  2. In the System window click on Advanced system settings in the left pane
  3. In the System Properties window select Advanced tab and click on Environment Variables… button given at the bottom of the window
  4. In the Environment Variables window you will notice two columns User variables for a username and System variables
  5. 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
  6. To remove a User variable click on the required User variable and then click on Delete button
  7. 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
    1. If Editing the PATH Variable, Seperate multiple entries with a semi-colon ";". You can reference other variables using the following format "%VAR_NAME%".
  8. Click OK button in the Environment Variables dialog window
  9. Click OK on System Properties window
  10. Close System window
  11. 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

  1. Open a Terminal Window
  2. Execute the following command: export VAR_NAME=VALUE

Setting Environment Variables Permanently

  1. Open a Terminal Window
  2. Execute the following command: vi ~/.bash_proflle
  3. Append the following to the end of the file: export VAR_NAME=VALUE
    1. If Editing the PATH Variable, Seperate multiple entries with a colon ":". You can reference other variables using the following format "{VAR_NAME}".
  4. Save & Close the file
  5. Execute the following command: source ~/.bash_proflle
    1. 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".



Published

03 July 2012

Tags