Add directory to path windows

I am trying to add C:\xampp\php to my system PATH environment variable in Windows.

I have already added it using the Environment Variables dialog box.

But when I type into my console:

C:\>path

it doesn’t show the new C:\xampp\php directory:

PATH=D:\Program Files\Autodesk\Maya2008\bin;C:\Ruby192\bin;C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;C:\PROGRA~1\DISKEE~2\DISKEE~1\;c:\Program Files\Microsoft SQL
Server\90\Tools\binn\;C:\Program Files\QuickTime\QTSystem\;D:\Program Files\TortoiseSVN\bin
;D:\Program Files\Bazaar;C:\Program Files\Android\android-sdk\tools;D:\Program Files\
Microsoft Visual Studio\Common\Tools\WinNT;D:\Program Files\Microsoft Visual Studio\Common
\MSDev98\Bin;D:\Program Files\Microsoft Visual Studio\Common\Tools;D:\Program Files\
Microsoft Visual Studio\VC98\bin

I have two questions:

  1. Why did this happen? Is there something I did wrong?
  2. Also, how do I add directories to my PATH variable using the console (and programmatically, with a batch file)?

Peter Mortensen's user avatar

asked Mar 3, 2012 at 12:58

Netorica's user avatar

8

Option 1

After you change PATH with the GUI, close and reopen the console window.

This works because only programs started after the change will see the new PATH.

Option 2

This option only affects your current shell session, not the whole system. Execute this command in the command window you have open:

set PATH=%PATH%;C:\your\path\here\

This command appends C:\your\path\here\ to the current PATH. If your path includes spaces, you do not need to include quote marks.

Breaking it down:

  • set – A command that changes cmd’s environment variables only for the current cmd session; other programs and the system are unaffected.
  • PATH= – Signifies that PATH is the environment variable to be temporarily changed.
  • %PATH%;C:\your\path\here\ – The %PATH% part expands to the current value of PATH, and ;C:\your\path\here\ is then concatenated to it. This becomes the new PATH.

Peter Mortensen's user avatar

answered Mar 3, 2012 at 13:03

JimR's user avatar

JimRJimR

15.6k2 gold badges20 silver badges26 bronze badges

12

WARNING: This solution may be destructive to your PATH, and the stability of your system. As a side effect, it will merge your user and system PATH, and truncate PATH to 1024 characters. The effect of this command is irreversible. Make a backup of PATH first. See the comments for more information.

Don’t blindly copy-and-paste this. Use with caution.

You can permanently add a path to PATH with the setx command:

setx /M path "%path%;C:\your\path\here\"

Remove the /M flag if you want to set the user PATH instead of the system PATH.

Notes:

  • The setx command is only available in Windows 7 and later.
  • You should run this command from an elevated command prompt.

  • If you only want to change it for the current session, use set.

StayOnTarget's user avatar

StayOnTarget

11.8k10 gold badges52 silver badges84 bronze badges

answered Feb 28, 2015 at 5:12

Nafscript's user avatar

NafscriptNafscript

5,1752 gold badges17 silver badges15 bronze badges

15

This only modifies the registry. An existing process won’t use these values. A new process will do so if it is started after this change and doesn’t inherit the old environment from its parent.

You didn’t specify how you started the console session. The best way to ensure this is to exit the command shell and run it again. It should then inherit the updated PATH environment variable.

Peter Mortensen's user avatar

answered Mar 3, 2012 at 13:23

Hans Passant's user avatar

Hans PassantHans Passant

924k146 gold badges1696 silver badges2536 bronze badges

6

You don’t need any set or setx command. Simply open the terminal and type:

PATH

This shows the current value of PATH variable. Now you want to add directory to it? Simply type:

PATH %PATH%;C:\xampp\php

If for any reason you want to clear the PATH variable (no paths at all or delete all paths in it), type:

PATH ;

Update

Like Danial Wilson noted in comment below, it sets the path only in the current session. To set the path permanently, use setx but be aware, although that sets the path permanently, but not in the current session, so you have to start a new command line to see the changes. More information is here.

To check if an environmental variable exist or see its value, use the ECHO command:

echo %YOUR_ENV_VARIABLE%

Peter Mortensen's user avatar

answered Jul 1, 2015 at 15:11

zar's user avatar

zarzar

11.4k15 gold badges97 silver badges178 bronze badges

6

I would use PowerShell instead!

To add a directory to PATH using PowerShell, do the following:

$PATH = [Environment]::GetEnvironmentVariable("PATH")
$xampp_path = "C:\xampp\php"
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$xampp_path")

To set the variable for all users, machine-wide, the last line should be like:

[Environment]::SetEnvironmentVariable("PATH", "$PATH;$xampp_path", "Machine")

In a PowerShell script, you might want to check for the presence of your C:\xampp\php before adding to PATH (in case it has been previously added). You can wrap it in an if conditional.

So putting it all together:

$PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine")
$xampp_path = "C:\xampp\php"
if( $PATH -notlike "*"+$xampp_path+"*" ){
    [Environment]::SetEnvironmentVariable("PATH", "$PATH;$xampp_path", "Machine")
}

Better still, one could create a generic function. Just supply the directory you wish to add:

function AddTo-Path{
param(
    [string]$Dir
)

    if( !(Test-Path $Dir) ){
        Write-warning "Supplied directory was not found!"
        return
    }
    $PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine")
    if( $PATH -notlike "*"+$Dir+"*" ){
        [Environment]::SetEnvironmentVariable("PATH", "$PATH;$Dir", "Machine")
    }
}

You could make things better by doing some polishing. For example, using Test-Path to confirm that your directory actually exists.

Mariano Desanze's user avatar

answered Mar 17, 2015 at 20:24

Ifedi Okonkwo's user avatar

Ifedi OkonkwoIfedi Okonkwo

3,4244 gold badges33 silver badges45 bronze badges

4

Safer SETX

Nod to all the comments on the @Nafscript’s initial SETX answer.

  • SETX by default will update your user path.
  • SETX ... /M will update your system path.
  • %PATH% contains the system path with the user path appended

Warnings

  1. Backup your PATHSETX will truncate your junk longer than 1024 characters
  2. Don’t call SETX %PATH%;xxx — adds the system path into the user path
  3. Don’t call SETX %PATH%;xxx /M — adds the user path into the system path
  4. Excessive batch file use can cause blindness1

The ss64 SETX page has some very good examples. Importantly it points to where the registry keys are for SETX vs SETX /M

User Variables:

HKCU\Environment

System Variables:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Usage instructions

Append to User PATH

append_user_path.cmd

@ECHO OFF
REM usage: append_user_path "path"
SET Key="HKCU\Environment"
FOR /F "usebackq tokens=2*" %%A IN (`REG QUERY %Key% /v PATH`) DO Set CurrPath=%%B
ECHO %CurrPath% > user_path_bak.txt
SETX PATH "%CurrPath%";%1

Append to System PATH

append_system_path.cmd. Must be run as administrator.

(It’s basically the same except with a different Key and the SETX /M modifier.)

@ECHO OFF
REM usage: append_system_path "path"
SET Key="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
FOR /F "usebackq tokens=2*" %%A IN (`REG QUERY %Key% /v PATH`) DO Set CurrPath=%%B
ECHO %CurrPath% > system_path_bak.txt
SETX PATH "%CurrPath%";%1 /M

Alternatives

Finally there’s potentially an improved version called SETENV recommended by the ss64 SETX page that splits out setting the user or system environment variables.


Example

Here’s a full example that works on Windows 7 to set the PATH environment variable system wide. The example detects if the software has already been added to the PATH before attempting to change the value. There are a number of minor technical differences from the examples given above:

@echo off
set OWNPATH=%~dp0
set PLATFORM=mswin

if defined ProgramFiles(x86)                        set PLATFORM=win64
if "%PROCESSOR_ARCHITECTURE%"=="AMD64"              set PLATFORM=win64
if exist "%OWNPATH%tex\texmf-mswin\bin\context.exe" set PLATFORM=mswin
if exist "%OWNPATH%tex\texmf-win64\bin\context.exe" set PLATFORM=win64

rem Check if the PATH was updated previously
echo %PATH% | findstr "texmf-%PLATFORM%" > nul

rem Only update the PATH if not previously updated
if ERRORLEVEL 1 (
  set Key="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
  for /F "USEBACKQ tokens=2*" %%A in (`reg query %%Key%% /v PATH`) do (
    if not "%%~B" == "" (
      rem Preserve the existing PATH
      echo %%B > currpath.txt

      rem Update the current session
      set PATH=%PATH%;%OWNPATH%tex\texmf-%PLATFORM%\bin
      
      rem Persist the PATH environment variable
      setx PATH "%%B;%OWNPATH%tex\texmf-%PLATFORM%\bin" /M
    )
  )
)

1. Not strictly true

Dave Jarvis's user avatar

Dave Jarvis

30.5k41 gold badges179 silver badges317 bronze badges

answered Dec 29, 2016 at 12:04

icc97's user avatar

icc97icc97

11.5k8 gold badges76 silver badges90 bronze badges

0

Handy if you are already in the directory you want to add to PATH:

set PATH=%PATH%;%CD%

It works with the standard Windows cmd, but not in PowerShell.

For PowerShell, the %CD% equivalent is [System.Environment]::CurrentDirectory.

Peter Mortensen's user avatar

answered Mar 18, 2016 at 16:09

nclord's user avatar

nclordnclord

1,2871 gold badge16 silver badges17 bronze badges

2

Aside from all the answers, if you want a nice GUI tool to edit your Windows environment variables you can use Rapid Environment Editor.

Try it! It’s safe to use and is awesome!

Peter Mortensen's user avatar

answered Feb 17, 2016 at 4:10

Netorica's user avatar

NetoricaNetorica

18.6k17 gold badges74 silver badges108 bronze badges

1

  • Command line changes will not be permanent and will be lost when the console closes.
  • The path works like first comes first served.
  • You may want to override other already included executables. For instance, if you already have another version on your path and you want to add different version without making a permanent change on path, you should put the directory at the beginning of the command.

To override already included executables;

set PATH=C:\xampp\php;%PATH%;

Peter Mortensen's user avatar

answered Sep 6, 2016 at 14:37

hevi's user avatar

hevihevi

2,4722 gold badges34 silver badges51 bronze badges

Use pathed from gtools.

It does things in an intuitive way. For example:

pathed /REMOVE "c:\my\folder"
pathed /APPEND "c:\my\folder"

It shows results without the need to spawn a new cmd!

Peter Mortensen's user avatar

answered Mar 19, 2019 at 9:37

womd's user avatar

womdwomd

3,12727 silver badges20 bronze badges

1

Checking the above suggestions on Windows 10 LTSB, and with a glimpse on the «help» outlines (that can be viewed when typing ‘command /?’ on the cmd), brought me to the conclusion that the PATH command changes the system environment variable Path values only for the current session, but after reboot all the values reset to their default- just as they were prior to using the PATH command.

On the other hand using the SETX command with administrative privileges is way more powerful. It changes those values for good (or at least until the next time this command is used or until next time those values are manually GUI manipulated… ).

The best SETX syntax usage that worked for me:

SETX PATH "%PATH%;C:\path\to\where\the\command\resides"

where any equal sign ‘=’ should be avoided, and don’t you worry about spaces! There isn’t any need to insert any more quotation marks for a path that contains spaces inside it — the split sign ‘;’ does the job.

The PATH keyword that follows the SETX defines which set of values should be changed among the System Environment Variables possible values, and the %PATH% (the word PATH surrounded by the percent sign) inside the quotation marks, tells the OS to leave the existing PATH values as they are and add the following path (the one that follows the split sign ‘;’) to the existing values.

Peter Mortensen's user avatar

answered Nov 22, 2016 at 20:34

such_ke_nasdeeq's user avatar

1

Regarding point 2, I’m using a simple batch file that is populating PATH or other environment variables for me. Therefore, there isn’t any pollution of environment variables by default. This batch file is accessible from everywhere so I can type:

mybatchfile

Output:

-- Here all environment variables are available

And:

php file.php

Peter Mortensen's user avatar

answered Oct 30, 2015 at 14:22

Grzegorz Gajos's user avatar

3

The below solution worked perfectly.

Try the below command in your Windows terminal.

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

SUCCESS: Specified value was saved.

You can refer to more on here.

Peter Mortensen's user avatar

answered Jun 5, 2021 at 13:42

Surendra Babu Parchuru's user avatar

Use these commands in the Bash shell on Windows to append a new location to the PATH variable

PATH=$PATH:/path/to/mydir

Or prepend this location

PATH=/path/to/mydir:$PATH

In your case, for instance, do

PATH=$PATH:C:\xampp\php

You can echo $PATH to see the PATH variable in the shell.

Peter Mortensen's user avatar

answered Sep 1, 2021 at 6:48

kiriloff's user avatar

kiriloffkiriloff

25.7k37 gold badges151 silver badges230 bronze badges

2

If you run the command cmd, it will update all system variables for that command window.

answered Oct 17, 2018 at 2:06

Pranav Sharma's user avatar

1

In a command prompt you tell Cmd to use Windows Explorer’s command line by prefacing it with start.

So start Yourbatchname.

Note you have to register as if its name is batchfile.exe.

Programs and documents can be added to the registry so typing their name without their path in the Start — Run dialog box or shortcut enables Windows to find them.

This is a generic reg file. Copy the lines below to a new Text Document and save it as anyname.reg. Edit it with your programs or documents.

In paths, use \\ to separate folder names in key paths as regedit uses a single \ to separate its key names. All reg files start with REGEDIT4. A semicolon turns a line into a comment. The @ symbol means to assign the value to the key rather than a named value.

The file doesn’t have to exist. This can be used to set Word.exe to open Winword.exe.

Typing start batchfile will start iexplore.exe.

REGEDIT4
;The bolded name below is the name of the document or program, <filename>.<file extension>

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\Batchfile.exe]

; The @ means the path to the file is assigned to the default value for the key.
; The whole path in enclosed in a quotation mark ".

@="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""

; Optional Parameters. The semicolon means don't process the line. Remove it if you want to put it in the registry

; Informs the shell that the program accepts URLs.

;"useURL"="1"

; Sets the path that a program will use as its' default directory. This is commented out.

;"Path"="C:\\Program Files\\Microsoft Office\\Office\\"

You’ve already been told about path in another answer. Also see doskey /? for cmd macros (they only work when typing).

You can run startup commands for CMD. From Windows Resource Kit Technical Reference

AutoRun

HKCU\Software\Microsoft\Command Processor

Data type Range Default value
REG_SZ  list of commands  There is no default value for this entry.

Description

Contains commands which are executed each time you start Cmd.exe.

Peter Mortensen's user avatar

answered Dec 21, 2016 at 1:08

A better alternative to Control Panel is to use this freeware program from SourceForge called Pathenator.

However, it only works for a system that has .NET 4.0 or greater such as Windows 7, Windows 8, or Windows 10.

Peter Mortensen's user avatar

answered Aug 28, 2017 at 1:24

Bimo's user avatar

BimoBimo

6,0052 gold badges39 silver badges62 bronze badges

0

As trivial as it may be, I had to restart Windows when faced with this problem.

I am running Windows 7 x64. I did a manual update to the system PATH variable. This worked okay if I ran cmd.exe from the stat menu. But if I type «cmd» in the Windows Explorer address bar, it seems to load the PATH from elsewhere, which doesn’t have my manual changes.

(To avoid doubt — yes, I did close and rerun cmd a couple of times before I restarted and it didn’t help.)

Peter Mortensen's user avatar

answered Oct 20, 2019 at 18:03

svinec's user avatar

svinecsvinec

6798 silver badges9 bronze badges

3

How to open the Environment Variables window from cmd.exe/Run… dialog

  • SystemPropertiesAdvanced and click «Environment Variables», no UAC
  • rundll32 sysdm.cpl,EditEnvironmentVariables direct, might trigger UAC

Via Can the environment variables tool in Windows be launched directly? on Server Fault.

How to open the Environment Variables window from Explorer

  1. right-click on «This PC»
  2. Click on «Properties»
  3. On the left panel of the window that pops up, click on «Advanced System Settings»
  4. Click on the «Advanced» tab
  5. Click on «Environment Variables» button at the bottom of the window

You can also search for Variables in the Start menu search.

Reference images how the Environment Variables window looks like:

Windows 10

Environment Variables window on Windows 10
via

Windows 7

Environment Variables window on Windows 7
via

Windows XP

Environment Variables window on Windows
via

  1. I have installed PHP that time. I extracted php-7***.zip into C:\php</i>

  2. Back up my current PATH environment variable: run cmd, and execute command: path >C:\path-backup.txt

  3. Get my current path value into C:\path.txt file (the same way)

  4. Modify path.txt (sure, my path length is more than 1024 characters, and Windows is running few years)

  • I have removed duplicates paths in there, like ‘C:\Windows; or C:\Windows\System32; or C:\Windows\System32\Wbem; — I’ve got twice.
  • Remove uninstalled programs paths as well. Example: C:\Program Files\NonExistSoftware;
  • This way, my path string length < 1024 :)))
  • at the end of the path string, add ;C:\php\
  • Copy path value only into buffer with framed double quotes! Example: «C:\Windows;****;C:\php» No PATH= should be there!!!
  1. Open Windows PowerShell as Administrator (e.g., Win + X).

  2. Run command:

    setx path "Here you should insert string from buffer (new path value)"

  3. Rerun your terminal (I use «Far Manager») and check:

    php -v

Peter Mortensen's user avatar

answered Oct 24, 2018 at 20:50

Serb's user avatar

SerbSerb

214 bronze badges

In my case it was just that I copied the path from the properties dialog box in Windows and it contained a blank character or something else in the text so it was not recognized. I pasted the path text in a plain text file and removed everything to the sides and my variable was recognized.

answered Jul 28 at 15:24

S. Feunmajer's user avatar

On Windows 10, I was able to search for set path environment variable and got these instructions:

  1. From the desktop, right-click the very bottom-left corner of the screen to get the Power User Task Menu.
  2. From the Power User Task Menu, click System.
  3. In the Settings window, scroll down to the Related settings section and click the System info link.
  4. In the System window, click the Advanced system settings link in the left navigation panel.
  5. In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.
  6. In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below:

C:\Program Files;C:\Winnt;C:\Winnt\System32

The first time I searched for it, it immediately popped up the System Properties Window. After that, I found the above instructions.

answered Nov 12, 2020 at 1:38

Janin's user avatar

JaninJanin

2921 gold badge2 silver badges7 bronze badges

If you’re a coder or programmer, you probably spend a decent amount of time using the command prompt to execute programs or compile code. In order to complete those tasks, you most likely have to use a command from a library or software package installed (like Python) on your system.

By default, most of these programs will add their own custom shortcuts to the Windows environment variables. The most used environment variable in Windows is probably the PATH variable. It basically allows you to run any executables that are located inside the paths specified in the variable at the command prompt without having to give the full path to the executable.

In this article, I’ll show you how you can add more paths to the Windows PATH variable in case you want to run executables from your own custom directories.  It’s worth noting that the procedure below is for Windows 10, but it’s almost exactly the same for Windows 7 also.

Add Directories to PATH Variable

To get started, right-click on the Computer or This PC icon on the desktop and select Properties. If you don’t have that icon on your desktop already, you can add any missing desktop icons easily.

On the System dialog page, you’ll see an Advanced system settings link on the left-hand side.

This will bring up the System Properties dialog, which should already be open to the Advanced tab. Go ahead and click on the Environment Variables button at the very bottom.

On the Environment Variables dialog, you’ll see two sets of variables: one for user variables and the other for system variables. Both lists have the PATH variable, so you have to decide which one to edit.

If you only need the commands for your own user account, then edit the user variable. If you need it to work across the computer system regardless of which user is logged in, then edit the system variable. Click on Path and then click on Edit.

On the Edit environment variable dialog, you’ll see a list of all the paths that are currently in the PATH variable. As you can see, Node.js and Git already added their paths so that I can run Git commands and Node.js commands from anywhere while in the command prompt.

To add a new path, simply click on New and it’ll add a new line to the bottom of the list. If you know the path, simply type it in or copy and paste it. If you prefer, you can also click Browse and then navigate to the desired path.

To edit any path, simply select it and then click on the Edit button. You can also delete paths using the Delete button. Note that you can also move items up and down on the list. When you type a command at the command prompt, Windows has to search through each directory stored in the PATH variable to see if that executable exists or not. If you want your executable to be found faster, just move that path up to the top of the list.

This can also come in handy if you have multiple versions of the same command in different paths and need to have one run instead of the other. The one that shows up higher in the list will be run when you type in the command.

Lastly, if you click on Edit text, it will load a dialog where you can edit the Path variable using the old interface where all the paths are listed in one text box.

That’s all there is to it! If you want to learn more about environment variables, make sure to check out my post on how to create your own custom environment variables. Enjoy!


Download Article

A simple guide to adding a directory to the Windows 10/11 path variable


Download Article

  • Windows 7–11
  • |

  • Windows XP
  • |

  • Warnings

The PATH environment variable specifies in which directories the Windows command line looks for executable binaries. The process for changing it is not obvious, but it’s not too hard. Read on to learn how to change PATH.

Things You Should Know

  • Adding a directory to your path makes it possible to run programs from the command line without typing the full path.
  • To access your path settings, open Settings, type «path,» then click «Edit the System Environment Details.»
  • While adding directories to the path is simple, don’t remove any existing path directories.
  1. Image titled Change the Path Environment Variable Method2 step1.png

    1

    Open the «settings» application. This can be done by pressing the Windows key and clicking the gear icon in the «Start» menu. You can also search «settings» in Cortana or in the «Start» menu.

  2. Image titled Change the Path Environment Variable Method2 step2.png

    2

    Search «path» in the settings menu.

    Advertisement

  3. Image titled Change the Path Environment Variable Method2 step3.png

    3

    Select Edit the System Environment Details. This option should be below Show Full Path in Title Bar and above Edit the Environment Details for your Account. A menu titled «System Properties» should pop up.

  4. Image titled Change the Path Environment Variable Method2 Step4.png

    4

    Click Environment Variables. This should be on the right-hand side of the menu below the Startup and Recovery section.

  5. Image titled Change the Path Environment Variable Method2 Step5.png

    5

    Select Path. You should not have to scroll down to find this option. It is in between two options titled OS and PATHEXT.

  6. Image titled Change the Path Environment Variable Method2 Step6.png

    6

    Click Edit, and proceed to edit the PATH environment variable.

    Warning! Unless you want to potentially destroy your PC’s system, DO NOT edit this variable unless you know what you’re doing.

  7. 7

    Select OK once you’re done editing. This will save any changes you may have made.

  8. Advertisement

  1. Image titled Windows my computer desktop screenshot.png

    1

    Create a shortcut to «My Computer». Click on «Start», mouse over «My Computer», right-click on it, and select «Show on Desktop».

  2. Image titled Windows my computer properties.png

    2

    Right-click on the shortcut and select Properties. A window will open.

  3. Image titled Windows properties environment variables.png

    3

    Switch to the Advanced tab. In that tab, click on Environment Variables. Another window will open.

  4. Image titled Windows edit path environment variable v2.png

    4

    Scroll down until you see «Path». Select it and click on Edit. A third window will open.

  5. Image titled Windows append to path environment variable.png

    5

    Edit the PATH environment variable. Unless you really know what you’re doing, don’t remove what’s already there, only append to it. For example, you could add another directory by appending: ;C:\path\to\directory, with «\path\to\directory» being the actual path to the directory.

  6. Image titled Windows environment variable editing press ok.png

    6

    Click on OK. When the window closes, there should be a short delay because the environment variable is being updated. After that, you can press OK to close the other two windows, too.

  7. Image titled Windows cmd echo path envvar.png

    7

    Check that the environment variable changed. Open the command line by pressing Win+R, entering cmd, and pressing Enter. Type: echo %PATH%. The output should be your updated PATH environment variable.

  8. Advertisement

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

Thanks for submitting a tip for review!

  • Changing the PATH environment variable wrongly can cause your system to stop working correctly. You should have a basic understanding of what you’re doing before changing PATH.

Advertisement

About This Article

Thanks to all authors for creating a page that has been read 57,667 times.

Is this article up to date?

The Path environment variable in Windows is a crucial system variable that stores the location of directories containing executable programs. It enables you to run these programs from any command prompt or PowerShell window without specifying their full path.

This article will provide a detailed, step-by-step guide on how to add a folder to the Path environment variable in Windows 11 and Windows 10. By following this guide, you can easily and efficiently manage the system path on your computer.

Add Folder to Path Environment Variable in Windows 11 10

What is the “Path” Environment Variable?

The Path environment variable is a critical component of the Windows operating system, as it allows you to run executable programs from any command prompt or PowerShell window without specifying their full path. The variable is a string that contains a list of directory paths separated by semicolons (;). When you enter a command or attempt to run a program, the system searches through these directories in the order they are listed, looking for the executable file associated with the command or program.

The primary purpose of the Path environment variable is to enable users to run essential programs or commands without having to navigate to the specific directory containing the executable file each time. By including the necessary directories in the Path variable, you can simplify your workflow and increase productivity.

Related issue: Batch (.BAT) Files Not Running in Windows 11/10

Example of a Path environment variable

C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk1.8.0_281\bin

In the example above, the Path environment variable contains three directories. When a command is entered, the system will search for the executable file in the following order:

  1. C:\Windows\system32
  2. C:\Windows
  3. C:\Program Files\Java\jdk1.8.0_281\bin

If the executable is not found in any of these directories, the system will return an error message.

“[Program] is not recognized as an internal or external command” error

Example: Consider a scenario where you are attempting to run a command or program called “custom-command,” but the directory containing the “custom-command.exe” file has not been added to the Path environment variable. In this case, when you try to run “custom-command” from the command prompt or PowerShell, you may receive an error message similar to the following:

'custom-command' is not recognized as an internal or external command, operable program or batch file.

is not recognized as an internal or external command Windows 11

This error message indicates that the system could not find the executable associated with “custom-command” in any of the directories listed in the Path environment variable. To resolve this issue, you would need to add the directory containing “custom-command.exe” to the Path variable, as described in the next section of this article.

Useful tip: How to List Installed Programs in Windows 11

How to add a folder to the “Path” Environment Variable in Windows 11 or 10

Adding a folder to the Path environment variable allows the system to recognize and execute programs stored in that folder without needing to navigate to it or specify its full path. The following elaborates on the three methods for adding a folder to the Path environment variable:

Using System Properties

This method involves using the graphical user interface (GUI) of the System Properties window to edit the Path variable.

  1. Press Windows + X and select “System” from the context menu that appears.
  2. In the System window, click on “Advanced system settings” in the right panel.Windows 11 advanced system settings
  3. In the System Properties dialog, switch to the “Advanced” tab and click on the “Environment Variables” button.View Environment Variables Windows 11
  4. Under the “System variables” section, scroll down and locate the “Path” variable. Select it and click on the “Edit” button. This will open the “Edit environment variable” window.Add Directory to Path Environment Variable Windows 11 10
  5. In this window, you will see a list of existing directories included in the Path variable. To add a new folder path, click on the “New” button and type or paste the folder path you want to include. Tip: To avoid errors when entering the folder path, use the “Copy as Path” feature instead of manually typing the full path. Make sure to use an absolute path, which starts from the root directory (e.g., C:\Users\YourUsername\custom-folder). Add Folder to Path Environment Variable in Windows 11 10
  6. Once you have added the folder path, click “OK” to save your changes. The new folder is now included in the Path environment variable, and the system will search this folder when looking for executable files associated with entered commands.

See also: Change File(s) Date & Timestamp via CMD or PowerShell

Using Command Prompt

In this method, you will use the Command Prompt to modify the Path environment variable.

  1. Open a Command Prompt with administrative privileges by right-clicking on the Start button, selecting “Windows Terminal (Admin)“, and then choosing “Command Prompt” from the dropdown menu.Open Command Prompt from Windows Terminal
  2. Enter the following command, replacing “YourFolderPath” with the folder path you want to add:
    setx PATH "%PATH%;YourFolderPath"

    This command appends the new folder path to the existing Path variable in the local environment. It is essential to include the “%PATH%;” part to preserve the current paths in the variable.
    To add the folder path to the system environment and prevents the system Path from being duplicated in the user Path, use the following command with the /M option:

    setx /M PATH "%PATH%;YourFolderPath"

    Add Folder to Path Environment Variable CMD

  3. Close the Command Prompt and reopen it to see the changes. The new folder is now included in the Path environment variable.

Using PowerShell

This method involves using PowerShell to update the Path environment variable.

  1. Open PowerShell with administrative privileges by right-clicking on the Start button and selecting “Windows Terminal (Admin)”.
  2. Enter the following command, replacing “YourFolderPath” with the folder path you want to add:
    [Environment]::SetEnvironmentVariable("Path",
    [Environment]::GetEnvironmentVariable("Path",
    [EnvironmentVariableTarget]::Machine) + ";YourFolderPath",
    [EnvironmentVariableTarget]::Machine)
    

    Add Folder to Path Environment Variable PowerShell
    This command retrieves the current Path variable, appends the new folder path, and then sets the updated Path variable. The “;YourFolderPath” part adds the new folder path after the existing paths.

  3. Close PowerShell and reopen it to see the changes. The new folder is now included in the Path environment variable.

Note: If you need to enter a multi-line command in PowerShell, you can use Shift + Enter to create a new line without executing the command. This way, you can enter the entire block of commands one line at a time. Only press Enter to execute when the whole block of commands has been entered. This technique is useful when working with lengthy commands or scripts.

By using any of these three methods, you can successfully add a folder to the Path environment variable in Windows 11 and Windows 10. This allows you to execute programs stored in the added folder without specifying their full path in the command prompt or PowerShell.

Verifying the changes

To verify that the folder has been added to the Path environment variable, open a new Command Prompt window and enter the following command:

echo %PATH%

Check the output and ensure that the folder path you added is present in the list of directories.

Check Path Environment Variable Windows 11 10

Common issues and troubleshooting tips

When working with the Path environment variable in Windows 11 or Windows 10, you may encounter certain issues or difficulties. This section provides an overview of some common problems and offers troubleshooting tips to help you resolve them.

  • If you encounter issues with adding a folder to the Path environment variable, double-check the folder path for typos or incorrect formatting. The folder path should be absolute and not contain any spaces or special characters.
  • Keep in mind that any changes you make to the Path environment variable will only apply to new Command Prompt or PowerShell sessions. Close and reopen the respective terminal to apply the changes.
  • If you still face issues, it is possible that the folder path you added is not being recognized due to conflicts with other paths or software. Review the existing paths in the Path environment variable and remove any duplicate or outdated entries.

Summary

Adding a folder to the Path environment variable in Windows 11 and Windows 10 can significantly streamline your workflow and make it easier to access executables without specifying their full path. With the methods outlined in this article, you can quickly and efficiently manage the system path on your computer. Remember to verify your changes and troubleshoot any issues you may encounter to ensure smooth and efficient system performance.

To make it easy to run programs from the command line, you can add a directory or program to the Windows PATH. Here is how to do it.

Windows has several built-in environment variables responsible for several different features and makes your life a tad bit easier. One of the most popular and useful Windows Variables is the PATH variable. The PATH variable allows you to add directories of executables so that it is easy to use them via the command line.

Generally, you don’t have to use the command line much in Windows. However, some programs may require or function better when using them via the command line. For example, FFMPG is a command-line tool. As such, adding FFMPEG to Windows PATH will make it easy to use the FFMPEG tool to download streaming videos. Similarly, if you use a specific application or program from the command line, you can add that executable’s directory to the Windows PATH. That way, you don’t have to open the Command Prompt or PowerShell window in the executable folder. Instead, you can use the program command directly as the path is already added to the Windows PATH, and the operating system knows where to look.

So, without delay, let me show you how to add a directory or a program to Windows PATH in Windows 10 and 11.

What is the PATH variable in Windows?

PATH is one of the system variables in Windows. The primary function of PATH is to let Windows know where to look for a program when running it from the command line. By default, most system programs are added to the PATH variable. That is why you don’t have to specify the absolute program path or open the command line window in the program directory while running a command related to system applications.

You will also find the PATH variable in other operating systems like Linux and macOS.

Can I edit the PATH variable?

Yes. You can edit the Windows PATH variable from the Environment Variables screen.

There are two kinds of PATH variables in Windows. i.e., User PATH variable and System PATH variable. As you can guess, anything thing added to the User PATH variable is only applicable to your user account. To apply the path system-wide (all users), you must add the directory or program to the System PATH variable.

To add to PATH in Windows, we need to open the Environment Variables tool. Here is how.

  1. Press the Start key on your keyboard.
  2. Search and open “Edit the system environment variables.”
  3. Go to the “Advanced” tab.
  4. Click the “Environment variables” button.
  5. Select the “Path” variable under “User variables” or “System variables.”
  6. Click the “Edit” button.
  7. Press the “New” button.
  8. Type the full directory path of the program.
  9. Press “Enter” to confirm the path.
  10. Click “Ok.”
  11. Press the “Ok” button in the Environment Variables window.
  12. Click “Ok” in the System Variables window.

Detailed steps:

First, we need to open the Environment Variables tool. To do that, search for “Edit the system environment variables” and click on the result. Here, make sure you are in the “Advanced” tab, and click on the “Environment Variables” button.

open environment variables

The above action will open the “Environment Variables” window. Select the “Path” variable under the “User Variables” or “System Variables” section. To limit the path to your user account, select the Path variable under the User Variables section. To apply the path to all users. i.e., system-wide, select the Path variable under the System Variables section. I’m choosing the Path variable under the User Variables section.

After selecting the Path variable, click on the “Edit” button under that section.

edit Windows path

Now, click the “New” button to add a new path to Windows PATH.

add directory or program to Windows path variable

Type the full path of the executable directory and click the “Ok” button. For example, suppose the full executable path is “C:\users\windowsloop\app\program.exe,” you need to type “C:\users\windowsloop\app\” in the blank field. Next, click the “Ok” button to save the changes.

Click “Ok” in the Environment Variables section.

Press the “Ok” button in the System Properties window.

That is it. You have successfully added a directory or program to Windows PATH. From now on, you can start using that program directly in any command-line tool.

Important note: After adding a directory or program to Windows PATH, you must close and re-open the command line tools. Otherwise, they might not recognize the changes in the PATH variable.

I hope that helps.

If you are stuck or need some help, comment below, and I will try to help as much as possible.

  • Adbappcontrol exe скачать бесплатно для windows
  • Add an exception to the windows firewall for spacedesk
  • Add php to path windows
  • Adb что это за папка в windows 10
  • Address already in use windows