You are located in service: Software for the RWTH Aachen University

How to setup enviromental variables (MacOS)?

How to setup enviromental variables (MacOS)?

Kurzinformation

On macOS, a distinction must be made between permanent environment variables, which continue to exist even after a system reboot, and temporary variables, for which this does not apply.


Detailinformation

Temporary variables:

1. Can be set quite easily and quickly via the terminal:

2. Open terminal: e.g. search for it via Spotlight and open it.
set the variable with the command "export <variable_name>=<variable_value>".

Replace <variable_name> and <variable_value> with their respective values.

3. Use "echo $<variable_name> " to check if the variable was added.

 

Permanent variables:

1. Open Terminal: e.g. search for it via Spotlight search and open it

2. Then enter the command "sudo nano /etc/profile" and confirm. Afterwards an admin password must be entered. This is not displayed, which is normal.

3. In the now open editor add the line "export <variable_name>=<variable_value>" and for each additional variable add another line according to the above scheme.

Save with control + S and exit with control + X.

Replace <variable_name> and <variable_value> with the respective values.

Restart the computer or log in again, so that the variable is taken over.

last changed on 02/18/2022

How did this content help you?

Creative Commons Lizenzvertrag
This work is licensed under a Creative Commons Attribution - Share Alike 3.0 Germany License