DEV Community

How To Set Environment Variables For MacOS

List all environment variables

$printenv
Enter fullscreen mode Exit fullscreen mode

Check a specific environment variable

$echo $[variable name]
Enter fullscreen mode Exit fullscreen mode

Set emporary environment variable

Step 1 : Open ~/.bash_profile for add new environment variable

$open ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Step 2 : Add new environment variable to ~/.bash_profile

export [variable_name]=[variable_value]
Enter fullscreen mode Exit fullscreen mode

Step 3 : Save any changes to ~/.bash_profile
Step 4 : Use the source to execute the new ~/.bash_profile

$source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Set permanent environment variable

Step 1 : Open ~/.zshrc for add new environment variable

$open ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Step 2 : Add new environment variable to ~/.zshrc

export [variable_name]=[variable_value]
Enter fullscreen mode Exit fullscreen mode

Step 3 : Save any changes to ~/.zshrc
Step 4 : Use the source to execute the new ~/.bash_profile

$source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Unset environment variable

Use the unset command to remove an environment variable

$unset [variable_name]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)