MacOS Environment Variables
- To display the list of currently set environment variables:
1
printenv
- To display the value of any specific environment variable:
1
echo $[variable name]
- To check the value of the PATH variable which stores a list of directories with executable files:
1
echo $PATH
- To set a temporary environment variable:
1
export [variable_name]=[variable_value]
- To add value to an existing environment variable:
1
export [existing_variable_name]=[new_variable_value]:$[existing_variable_name]
Example:
1
export PATH=/Users/exec/tok:$PATH
- To set permanent environment variable
- Find the path to .bash_profile using:
1
~/.bash_profile
- Open the .bash_profile file with a text editor and add the new environmental variable to the end of the file using:
1
export [variable_name]=[variable_value]
- Save the file and refresh the terminal using the below command or restart the terminal.
1
source ~/.bash_profile
- Find the path to .bash_profile using:
- To unset the environmental variable:
1
unset [variable =_name]
This post is licensed under CC BY 4.0 by the author.