Setting Environment Variables
To configure your environment for applications, you may need to set environment variables. This guide provides instructions for setting environment variables in both macOS (Shell) and Windows (PowerShell and Windows Command Prompt).
macOS
Setting Environment Variables in Shell
Temporary Environment Variables
These environment variables will only be available in the current shell session.
To display the environment variable:
Permanent Environment Variables
To make environment variables persist across sessions, add them to your shell configuration file (e.g., .bashrc
, .bash_profile
, .zshrc
).
For Zsh:
To display the environment variable:
Windows
Setting Environment Variables in PowerShell
Temporary Environment Variables
These environment variables will only be available in the current PowerShell session.
To display the environment variable:
Permanent Environment Variables
To make environment variables persist across sessions, add them to your PowerShell profile script (e.g., Microsoft.PowerShell_profile.ps1
).
Add the following line to the profile script:
Save and close the file, then reload the profile:
To display the environment variable:
Setting Environment Variables in Windows Command Prompt
Temporary Environment Variables
These environment variables will only be available in the current Command Prompt session.
To display the environment variable:
Permanent Environment Variables
To make environment variables persist across sessions, you can use the setx
command:
Note: After setting an environment variable using setx
, you need to restart the Command Prompt or any applications that need to read the new environment variable.
To display the environment variable in a new Command Prompt session:
By following these steps, you can effectively set and display environment variables in macOS Shell, Windows Command Prompt, and PowerShell. This will ensure your environment is properly configured for your applications.
Was this page helpful?