Skip to content

/commands/cmd/set-path-environment-variable

Add a folder to PATH in cmd: set PATH for the session, setx or System Properties

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Command Prompt (cmd)
versions
Windows 10, Windows 11, Windows Server 2016+
os
windows

To add a folder to PATH for the current Command Prompt window, prepend or append it to the existing value:

cmd
set "PATH=C:\tools\bin;%PATH%"

The change disappears when the window closes and does not affect other windows. To make it permanent, edit the user or system Path in Settings > System > About > Advanced system settings > Environment Variables (or run rundll32 sysdm.cpl,EditEnvironmentVariables). Programs see the new value only when they are started after the change, so open a new terminal.

Session only

cmd
mkdir tools
> tools\greet.cmd echo @echo hello from greet
greet 2>&1
set "PATH=%CD%\tools;%PATH%"
greet
where greet

Output

'greet' is not recognized as an internal or external command,
operable program or batch file.
hello from greet

path without arguments prints the current value as PATH=.... Quoting the whole assignment (set "PATH=...;%PATH%") keeps parentheses in entries such as C:\Program Files (x86)\... from breaking the line inside if or for blocks.

Permanent: setx and its limits

cmd
setx PATH "C:\tools\bin;%PATH%"

A safer PowerShell version that appends to the user PATH only:

powershell
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
[Environment]::SetEnvironmentVariable('Path', "$user;C:\tools\bin", 'User')

After either change, open a new cmd or PowerShell window (or restart the program, such as VS Code) to pick up the new value. setx does not change the window it runs in.

Order matters

PATH is searched from left to right and the first match wins. Prepend (C:\new;%PATH%) to override an older copy of a tool, append (%PATH%;C:\new) to use it only when nothing else provides that name. Check the result with where.

Sources