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.

export VARIABLE_NAME="value"

To display the environment variable:

echo $VARIABLE_NAME

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:

echo 'export VARIABLE_NAME="value"' >> ~/.zshrc
source ~/.zshrc

To display the environment variable:

echo $VARIABLE_NAME

Windows

Setting Environment Variables in PowerShell

Temporary Environment Variables

These environment variables will only be available in the current PowerShell session.

$env:VARIABLE_NAME = "value"

To display the environment variable:

echo $env:VARIABLE_NAME

Permanent Environment Variables

To make environment variables persist across sessions, add them to your PowerShell profile script (e.g., Microsoft.PowerShell_profile.ps1).

notepad $PROFILE

Add the following line to the profile script:

$env:VARIABLE_NAME = "value"

Save and close the file, then reload the profile:

. $PROFILE

To display the environment variable:

echo $env:VARIABLE_NAME

Setting Environment Variables in Windows Command Prompt

Temporary Environment Variables

These environment variables will only be available in the current Command Prompt session.

set VARIABLE_NAME=value

To display the environment variable:

echo %VARIABLE_NAME%

Permanent Environment Variables

To make environment variables persist across sessions, you can use the setx command:

setx VARIABLE_NAME "value"

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:

echo %VARIABLE_NAME%

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.