This page contains promotions.

How to Set Environment Variables on Windows | PATH, GUI & CLI

Windowsの環境変数設定画面

If you install a development tool and then see "command not recognized" in the terminal, the most likely cause is that the tool's folder isn't in the PATH environment variable. Windows makes it straightforward to manage environment variables through a GUI, but understanding when changes take effect, and the difference between system and user variables, saves a lot of troubleshooting time. This guide covers how to view current variables, add folders to PATH via the GUI, create or edit variables with the command line, and apply changes properly.

Table of Contents

  1. Environment Variable Basics
    1. What Environment Variables Do
    2. System Variables vs User Variables
  2. How to View Environment Variables
    1. Command Prompt
    2. PowerShell
  3. Setting Environment Variables via the GUI
    1. Opening the Environment Variables Editor
    2. Adding a Folder to PATH
  4. Setting Environment Variables via the Command Line
    1. Persistent Settings with setx
    2. Using PowerShell
  5. How to Apply Changes
  6. Frequently Asked Questions
  7. Summary

Environment Variable Basics

Environment variables are key-value pairs that Windows and applications read for configuration settings.

What Environment Variables Do

Some common examples:

  • PATH: Command search path. Tools like python, git, and node only work from any folder if their install directory is listed here
  • TEMP / TMP: Location for temporary files
  • USERPROFILE: The current user's home folder (e.g., C:\Users\YourName)
  • APPDATA: Where apps store their settings
  • JAVA_HOME / PYTHONPATH: Tool-specific paths used by development environments

PATH is by far the most frequently needed variable for developers — a misconfigured PATH is almost always the reason a newly installed command isn't found.

System Variables vs User Variables

Environment variables fall into two scopes:

  • System variables: Apply to all users. Require administrator rights to change
  • User variables: Apply only to the current user. No admin rights needed

When adding a folder to PATH for personal use, edit the user PATH. If every user on the PC needs access, edit the system PATH. When both scopes define a variable with the same name, user variables take priority — except for PATH, where both are merged (system PATH comes first, then user PATH).

How to View Environment Variables

Before making changes, it's worth checking the current values.

Command Prompt

To display a specific variable:

echo %PATH%

To list all variables:

set

To filter by prefix (useful when there are many variables):

set PATH set JAVA

PowerShell

$env:PATH

Or to list everything:

Get-ChildItem Env:

To display each PATH folder on its own line for easy reading:

$env:PATH -split ';'

Setting Environment Variables via the GUI

The GUI is the clearest way to make changes, especially if you're editing PATH.

Opening the Environment Variables Editor

  1. Type environment variables in the Start menu search
  2. Select Edit the system environment variables
  3. The System Properties window opens
  4. Click the Environment Variables button

The dialog shows user variables in the top half and system variables in the bottom half.

Adding a Folder to PATH

To add a development tool's bin folder (or any folder) to PATH:

  1. Select Path under User variables (or System variables if all users need it)
  2. Click Edit
  3. The path list editor opens
  4. Click New
  5. Type or paste the full folder path (e.g., C:\Tools\bin)
  6. Click OK to close the path editor
  7. Click OK to close the Environment Variables dialog
  8. Click OK to close System Properties

Tip: Open the target folder in File Explorer, click the address bar, and press Ctrl + C to copy the exact path — paste it directly into the editor to avoid typos.

To create a brand new variable, click New under the relevant section and enter the variable name and value.

Setting Environment Variables via the Command Line

Useful when automating setup or working in scripts.

Persistent Settings with setx

setx writes environment variables that persist across sessions:

setx MY_VAR "Hello World"

This creates a user variable. To write a system variable, add /M and run as administrator:

setx MY_VAR "Hello World" /M

When adding to PATH, always include the existing PATH value to avoid overwriting it:

setx PATH "%PATH%;C:\NewFolder"

Note: setx has a 1024-character limit. If your PATH is already long, use the GUI instead to avoid truncation.

Using PowerShell

[Environment]::SetEnvironmentVariable("MY_VAR", "Hello World", "User")

The third argument controls scope: "User", "Machine" (system-wide, needs admin), or "Process" (current session only, not persisted).

To safely append to PATH:

$old = [Environment]::GetEnvironmentVariable("PATH", "User") [Environment]::SetEnvironmentVariable("PATH", $old + ";C:\NewFolder", "User")

How to Apply Changes

Changes to environment variables don't affect already-running processes. To use the new value:

  • Open a new terminal: Close and reopen Command Prompt or PowerShell
  • Restart Explorer: In Task Manager, restart explorer.exe to push system-wide changes
  • Restart the PC: The most reliable option

To use the new value temporarily in the current session without restarting:

Command Prompt:

set PATH=%PATH%;C:\NewFolder

PowerShell:

$env:PATH += ";C:\NewFolder"

These are session-only and won't persist after closing the terminal.

Frequently Asked Questions

Q. I edited PATH and now other apps have stopped working

A. You may have accidentally overwritten the existing PATH value. Open the environment variables editor and check the PATH entries. If entries are missing, restore from a system restore point or rebuild from another PC's PATH. Always back up the current PATH value before editing.

Q. I ran setx but the command still isn't found

A. setx only takes effect in new processes. Close the current terminal and open a fresh one, or restart the PC.

Q. What happens if the same variable exists in both user and system scope?

A. For most variables, the user variable wins. PATH is a special case — both are concatenated, with the system PATH listed first followed by the user PATH.

Q. Can I reference another variable inside a variable's value?

A. Yes. For example, adding %JAVA_HOME%\bin to PATH expands to whatever JAVA_HOME is set to. This lets you manage the root path in one place and reference it everywhere.

Q. How do I completely delete an environment variable?

A. In the GUI, select the variable and click Delete. From the command line, use setx MY_VAR "" to clear the value, or [Environment]::SetEnvironmentVariable("MY_VAR", $null, "User") in PowerShell to remove it entirely.

Summary

The clearest way to set environment variables on Windows is through the GUI — search for "environment variables" in the Start menu, open the editor, and add entries to PATH using the New button so you don't accidentally overwrite existing entries. For scripting and automation, use setx from Command Prompt or [Environment]::SetEnvironmentVariable() in PowerShell. Remember that changes only take effect in new processes, so reopen your terminal after making updates.