How to Open, Set, and Save Environment Variables (Windows, macOS, Linux)

🪟 How to Set Environment Variables in Windows

1. Open the Environment Variables Window

  • Right-click the Start menu and select System (or press Windows Key + X and choose System).

  • Click on Advanced system settings.

  • Click the Environment Variables button.

2. Add a New Environment Variable

  • Click New under the User variables or System variables section.

  • Enter the Variable name and Variable value.

  • Click OK.

3. Edit an Existing Environment Variable

  • Select the variable you want to modify and click Edit.

  • Update the Variable value and click OK.

4. Save and Apply

  • Click OK on all open dialog windows to save your changes.

  • Note: You must restart any currently open command prompts or applications for the changes to take effect.

🍎 How to Set Environment Variables in macOS

1. Open Terminal

  • Go to Applications → Utilities → Terminal.

2. Set Temporary Environment Variables (Current Session Only)

Bash
export VARIABLE_NAME=value
# Example: export PATH=$PATH:/new/path

3. Set Permanent Environment Variables

  • Open your shell profile file:

    • Bash shell: nano ~/.bash_profile or nano ~/.bashrc

    • Zsh shell (Default on newer macOS): nano ~/.zshrc

  • Add your environment variable to the file:

export VARIABLE_NAME=value

*   Press `Ctrl + O` to save (WriteOut) and `Ctrl + X` to exit.
*   Apply the changes immediately by running:
    ```bash
source ~/.bash_profile  # or source ~/.zshrc

🐧 How to Set Environment Variables in Linux

1. Open Terminal

2. Set Temporary Environment Variables (Current Session Only)

Bash
export VARIABLE_NAME=value

3. Set Permanent Environment Variables

  • User Level:

    • Open nano ~/.bashrc, nano ~/.bash_profile, or your active shell's configuration file.

    • Add export VARIABLE_NAME=value to the end of the file.

    • Save (Ctrl + O) and exit (Ctrl + X).

    • Apply the changes by running source ~/.bashrc (or the respective file).

  • System Level:

    • Open the environment file using sudo: sudo nano /etc/environment or sudo nano /etc/profile.

    • Add the variable in the following format:

VARIABLE_NAME=value

    *   Save and exit.
    *   Restart the system or log out and log back in to apply the changes.

---

### 🔍 How to Check Your Environment Variables

**Check a Specific Variable:**
*   **Windows (Command Prompt):**
    ```cmd
echo %VARIABLE_NAME%
  • macOS / Linux (Terminal):

echo $VARIABLE_NAME


**View All Environment Variables:**
*   **Windows:**
    ```cmd
set
  • macOS / Linux:

env

or

printenv

댓글

이 블로그의 인기 게시물

How to Set Up Fastlane for iOS

How to Ignore Info.plist in Xcode Projects on GitHub

How to Fix Shared Progress Issues Across Different Difficulty Levels in SQLite