Setting Global environment variables

Setting Global environment variables on Windows

For Windows users, you can change the environment variable the following ways.

Windows 10 and Windows 8

  • Search and select System (Control Panel).
  • Click on the Advanced system settings link and then click Environment Variables. Under the section System Variables, select the environment variable you want to edit, and click Edit.
  • If the environment variable you want doesn’t exist, click New.
  • Input the value of the environment variable in the Edit System Variable (or New System Variable) window, and click OK.

Windows 7

  • Right click the Computer icon on your desktop and choose Properties from the menu.
  • Click on the Advanced system settings link and then click Environment Variables. Under the section System Variables, select the environment variable you want to edit, and click Edit.
  • If the environment variable you want doesn’t exist, click New.
  • Input the value of the environment variable in the Edit System Variable (or New System Variable) window, and click OK.

Setting Global environment variables on macOS

It is a bit of a mystery for many Mac users how to create environment variables that will be available for all applications, including those launched from icons, etc.

The process involves creating (or editing, if it exists) a special environment.plist file in the users home directory. You can add the environment variable and it’s value here. Then you have to log out and in.

Create the plist file under ~/Library/LaunchAgents/:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
 <dict>
  <key>Label</key>
  <string>my.startup</string>
  <key>ProgramArguments</key>
  <array>
   <string>sh</string>
   <string>-c</string>
   <string>launchctl setenv PG_IMAGE_PATH /volumes/myProject/textures
     launchctl setenv YETI_INTERACTIVE_LICENSE 1</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  </dict>
</plist>

To activate the environment.plist (assuming you named it environment.plist), run

launchctl load ~/Library/LaunchAgents/environment.plist
launchctl start ~/Library/LaunchAgents/environment.plist

If it is already loaded and you have modified the plist file, see your updates by running

launchctl stop ~/Library/LaunchAgents/environment.plist
launchctl unload ~/Library/LaunchAgents/environment.plist
launchctl load ~/Library/LaunchAgents/environment.plist
launchctl start ~/Library/LaunchAgents/environment.plist

For further reference, see this stack overflow article which covers earlier releases of macOS.