How to add path to path variable in windows

I am trying to add C:xamppphp 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

I am trying to add C:xamppphp 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:xamppphp directory:

PATH=D:Program FilesAutodeskMaya2008bin;C:Ruby192bin;C:WINDOWSsystem32;C:WINDOWS;
C:WINDOWSSystem32Wbem;C:PROGRA~1DISKEE~2DISKEE~1;c:Program FilesMicrosoft SQL
Server90Toolsbinn;C:Program FilesQuickTimeQTSystem;D:Program FilesTortoiseSVNbin
;D:Program FilesBazaar;C:Program FilesAndroidandroid-sdktools;D:Program Files
Microsoft Visual StudioCommonToolsWinNT;D:Program FilesMicrosoft Visual StudioCommon
MSDev98Bin;D:Program FilesMicrosoft Visual StudioCommonTools;D:Program Files
Microsoft Visual StudioVC98bin

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:yourpathhere

This command appends C:yourpathhere 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:yourpathhere – The %PATH% part expands to the current value of PATH, and ;C:yourpathhere 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.1k2 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:yourpathhere"

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

10.9k10 gold badges49 silver badges75 bronze badges

answered Feb 28, 2015 at 5:12

Nafscript's user avatar

NafscriptNafscript

4,9572 gold badges16 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

912k145 gold badges1670 silver badges2507 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:xamppphp

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

10.9k13 gold badges90 silver badges171 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:xamppphp"
[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:xamppphp 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:xamppphp"
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,3064 gold badges31 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:

HKCUEnvironment

System Variables:

HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment

Usage instructions

Append to User PATH

append_user_path.cmd

@ECHO OFF
REM usage: append_user_path "path"
SET Key="HKCUEnvironment"
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="HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment"
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%textexmf-mswinbincontext.exe" set PLATFORM=mswin
if exist "%OWNPATH%textexmf-win64bincontext.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="HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment"
  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%textexmf-%PLATFORM%bin
      
      rem Persist the PATH environment variable
      setx PATH "%%B;%OWNPATH%textexmf-%PLATFORM%bin" /M
    )
  )
)

1. Not strictly true

Dave Jarvis's user avatar

Dave Jarvis

29.9k39 gold badges177 silver badges310 bronze badges

answered Dec 29, 2016 at 12:04

icc97's user avatar

icc97icc97

10.6k8 gold badges68 silver badges88 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,2271 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.1k17 gold badges72 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:xamppphp;%PATH%;

Peter Mortensen's user avatar

answered Sep 6, 2016 at 14:37

hevi's user avatar

hevihevi

2,3501 gold badge32 silver badges51 bronze badges

Use pathed from gtools.

It does things in an intuitive way. For example:

pathed /REMOVE "c:myfolder"
pathed /APPEND "c:myfolder"

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

2,97325 silver badges19 bronze badges

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

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:pathtowherethecommandresides"

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

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_MACHINESoftwareMicrosoftWindowsCurrentVersionApp PathsBatchfile.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

HKCUSoftwareMicrosoftCommand 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

5,5972 gold badges35 silver badges57 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

6298 silver badges9 bronze badges

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:xamppphp

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.2k36 gold badges143 silver badges222 bronze badges

1

  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:WindowsSystem32; or C:WindowsSystem32Wbem; — I’ve got twice.
  • Remove uninstalled programs paths as well. Example: C:Program FilesNonExistSoftware;
  • 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

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

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:WinntSystem32

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

2721 gold badge2 silver badges7 bronze badges


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:pathtodirectory, with «pathtodirectory» 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 34,889 times.

Is this article up to date?

PATH is an environment variable that specifies a set of directories, separated with semicolons (;), where executable programs are located.

In this note i am showing how to print the contents of Windows PATH environment variable from the Windows command prompt.

I am also showing how to add a directory to Windows PATH permanently or for the current session only.

Cool Tip: List environment variables in Windows! Read More →

Print the contents of the Windows PATH variable from cmd:

C:> path

– or –

C:> echo %PATH%

The above commands return all directories in Windows PATH environment variable on a single line separated with semicolons (;) that is not very readable.

To print each entry of Windows PATH variable on a new line, execute:

C:> echo %PATH:;=&echo.%

Cool Tip: Set environment variables in Windows! Read More →

Add To Windows PATH

Warning! This solution may be destructive as Windows truncates PATH to 1024 characters. Make a backup of PATH before any modifications.

Save the contents of the Windows PATH environment variable to C:path-backup.txt file:

C:> echo %PATH% > C:path-backup.txt

Set Windows PATH For The Current Session

Set Windows PATH variable for the current session:

C:> set PATH="%PATH%;C:pathtodirectory"

Set Windows PATH Permanently

Run as Administrator: The setx command is only available starting from Windows 7 and requires elevated command prompt.

Permanently add a directory to the user PATH variable:

C:> setx path "%PATH%;C:pathtodirectory"

Permanently add a directory to the system PATH variable (for all users):

C:> setx /M path "%PATH%;C:pathtodirectory"

Info: To see the changes after running setx – open a new command prompt.

Download PC Repair Tool to quickly find & fix Windows errors automatically

Environment Variables are responsible for storing information about the OS’s environment. Different apps and programs require different configurations and it is the job of Windows to ensure that each of them has the environment best suitable for them. Simply speaking, these Environment Variables are data storing facilities. A PATH variable is one of the most useful of the kind and helps you to run any executable found within Paths without having to give the full path to the executable. In this article, we will be discussing how you can manually add or edit existing PATH environment variables on Windows 11 or Windows 10.

An Environment variable is useful in the sense that it influences how software processes take place. The data stored in them play an important role in the process. Our tutorial will help you set up PATH variables so that you can run executables from your custom directories. These PATH variables store shortcuts, so you can create them for the programs of your choice. A prerequisite to push PATH variables through is to grant administrative privileges, so make sure you have them enabled. If you want a more detailed explanation of what System & User Environment Variables are, you can read the linked post.

How to set PATH variables manually on Windows 11/10

Without further ado, let’s see how you can add or edit a PATH Environment Variable in Windows 11/10:

  1. Click on the Search menu on the Taskbar and open the Windows Settings
  2. From the Settings panel, click on the System option from the left menu pane
  3. Go to About and further click on Advanced System Settings. This will open a dialog box named System Properties
  4. Here, click on the Advanced tab and further click on the Environment Variables button on the bottom-right
  5. This will open the Environment Variables panel. Here, variables will be divided into two categories: System and User Variables. The former is applicable for system-wide changes while the latter is used to make modifications to the environment of a particular user. Make a decision based on the purpose of creating or editing a PATH variable and select PATH from a section
  6. Follow this by clicking on the Edit button

add or edit a PATH Environment Variable in Windows

You can now modify the existing route lines with the ones you want your computer to access. This stuff may seem overwhelming to some of you and has very deep implications for some important PC processes, so you’re advised to express utmost caution.

In order to add a new route, you can click on the ‘New’ button. You can delete a Path the same way. Here, you can just paste the Path of your choice, and if you’re unsure of it, then you can use the Surf option to go about searching for it. Once you’re done, click on Ok and a new PATH variable will now exist.

Our guide here explains how you can add Environment Variables to your Windows Context Menu.

Read: How to see Names and Values of Environment Variables in Windows

How do I change Environment Variables without admin rights?

Granting administrative rights may not be as easy when the PC isn’t yours, but you can still make changes to your environment variables. Via the Control Panel, you can modify the environment variables on a user account, but not System variables. Here’s how you can do that:

  • Open the Control Panel
  • Select to view them as ‘Small icons’ and click on User Accounts
  • Here, you’ll see an option to your left named ‘Change my environment variables’
  • This will open the same Environment Variables dialog box as before, except now the System Variables aren’t accessible and you can only make changes to User variables

TIP: Rapid Environment Editor is a powerful free Environment Variables Editor for Windows.

How do I change the Path in Windows Command Prompt?

A command line on your Windows Terminal (Command Prompt) can help you add a Path to your Path environment variable. The changes that we have discussed above can be implemented via the Command Prompt as well, but again, are limited to the User’s environment only. Here’s how:

  • Search ‘CMD’ on the Taskbar search menu and select to run it as the administrator
  • Enter the command ‘Pathman /au’ and follow it by the Path to the directory you want to append.
  • Similarly, you can use a ‘Pathman/ru’ command to delete an existing Path to a directory

We hope that this post was helpful for you and that you can now take care of your Path environment variables with ease.

Ezoic

Shiwangi loves to dabble with and write about computers. Creating a System Restore Point first before installing new software, and being careful about any third-party offers while installing freeware is recommended.

Sometimes we need to tell Windows where to look for a particular executable file or script. Windows provides a means to do this through the Path Environment Variable. The Path Environment Variable essentially provides the OS with a list of directories to look in for a particular .exe or file when the simple name of the file is entered at the command prompt.

For example, the Notepad.exe application resides in the C:Windowssystem32 directory. However, if we wish to open the Notepad application via the Windows Command Line, we need only type:

Opening Notepad.exe From the Windows Command Line:
C:UsersJohn> notepad

This works because the Path variable on Windows by default contains a list of directories where application files and scripts are likely to be located. Each directory in the list is separated by a semi-colon.

Similarly, there is another environment variable, PATHEXT which specifies a list of file extensions which might be found when searching for the proper file within the paths in the Path variable. This is why we are able to type simply “Notepad” at the command prompt, instead of Notepad.exe.

Windows will first search the current directory (where the command prompt is a the time the command is executed) to find a name matching the one typed into the terminal, and then search the directories in the Path variable in order, beginning with the most likely locations, and continue until either a matching file name is located, or else return the “… is not recognized blah blah” message at the terminal.

Once a file with a matching name is located, Windows attempts to match the file extension (if one is present), again in the order specified in the PATHEXT variable. If a match is found, the file is processed accordingly.

There are both User-specific and machine-level PATH variables. Machine Path variables are available globally across the machine, and can only be modified by administrators.  User Environment variables can be modified by both administrators, and the user with which the current profile is associated.

Adding a Directory to the User Path Variable from the Command Line

Any user can modify their own PATH variable from the Command Line (unless they have been specifically denied this ability by an administrator).

For example, when we wish to use SQLite from the Windows Command Line, we download the SQLite binaries, and place them in the directory of choice. However, in order to use the SQLite Command Line application without either navigating directly to the folder in which we placed it, or entering the  full file path into our Windows Command Line, we need to add the directory containing the SQLite.exe to our User or System PATH environment variable.

Let’s say a user has downloaded the sqlite3.dll and sqlite3.exe binaries and located them in the directory C:SQLite.

Now, in order to invoke the sqlite3.exe from the command line, we need to add the C:SQLite directory to our PATH environment variable. We can do this from the command line by using the setx command:

The setx Command – Syntax:
C:UsersJohn> setx "%path%;C:SQLite"

When we modify environment variables using setx, the changes are not available in the current Console session – in other words, in order to see our changes, we need to exit, and open a new Console window. Then, we can use the following technique:

We can examine the contents of the PATH variable by typing:

Output PATH Variable to the Console:
C:UsersJohn> echo %PATH%

Which gives the output:

Results of Echo %PATH% Command:
C:UsersJohn>echo %PATH%
C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32Wind
owsPowerShellv1.0;C:Program Files (x86)Windows Kits8.1Windows Performance
Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Files
Microsoft SQL Server110DTSBinn;C:Program Files (x86)Microsoft SQL Server1
10ToolsBinn;C:Program Files (x86)Microsoft SQL Server110ToolsBinnManage
mentStudio;C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPriv
ateAssemblies;C:Program Files (x86)Microsoft SQL Server110DTSBinn;C:Prog
ram Files (x86)Common FilesAcronisSnapAPI;C:Program Files (x86)Windows Liv
eShared;C:Program FilesCalibre2;C:Program FilesMicrosoftWeb Platform Inst
aller;C:UsersJohnAppDataRoamingnpm;C:Program Files (x86)nodejs;C:Progr
am Files (x86)Microsoft SDKsWindows AzureCLIwbin;C:Program Files (x86)GtkS
harp2.12bin;C:Program Files (x86)Microsoft SDKsTypeScript1.0;C:SQLite

We can see here that C:SQLite has now been added to the paths available to the current user.

Adding a Directory to the System Path Variable from the Command Line

In the previous section, we used the setx command to add a directory to the current user’s Path variable. Sometimes, we want to make variables available at the system, or machine level. In that case, we use the same setx command in conjunction with the /m flag. However, we need to run the Command Terminal as Administrator for this to work:

Add a Directory the the System PATH Variable Using the /m Flag:
C:UsersJohn> setx /m path "%path%;C:SQLite"

Adding a Directory to the Path Variable from the GUI

Or, we can do this using the GUI by navigating to Control Panel => All Control Panel Items => System, and then selecting the “Advanced System Settings” link:

Locate Advanced System Settings in Control Panels:

Control PanelAll Control Panel ItemsSystem

Then locate the “Environment Variables” button:

Open Environment Variables:

System Properties

Opening Environment Variables, we see the following:

Editing Environment Variables:

Environment Variables

Notice in the image above, there are two sections, User Variables for<Current User>, and System Variables.

Also note, there is not currently a Path variable for me, the current user. We will need to add one, and then add our new path to it:

Adding a User Path Variable in the Windows GUI:

add-path-variable

Once we hit OK, We see we have the single item added to our user path variable.

Added Path Variable to User Environment Variables:

New Environment Variables

For some reason, this works differently than when we do this from the Command Line, when we use the setx command from the terminal, the entirety of the system path variable is copied into the user path variable, including the new entry.

If we have Administrator permissions on our machine, we can do the same for the System PATH variable if we so choose.

Removing Directories from the PATH Variable

In some cases, we may need to remove a directory from our PATH variable. In these cases it is recommended to use the GUI, or edit the registry. It’s easiest to simply open the GUI, copy the contents of the PATH variable (either the User Path or the System Path) to a text editor, and remove the entries you want to delete. Then paste the remaining text back into the Edit Path window, and save.

Additional Resources and Items of Interest

  • Installing and Using SQLite on Windows
  • Getting Started with Git for the Windows Developer (Part I)
  • Basic Git Command Line Reference for Windows Users
  • Git: Interactively Stage Portions of a Single Changed File for Commit Using git add -p

The most efficient way to get most things done on Windows is via the graphical interface. Every now and then, though, you have to turn to the command line for troubleshooting, programming, or just working on your nerd cred.

But if you’re trying to run something that’s not natively part of Windows, you’ll need to add it to your PATH variable. That tells your system where to look for executables when you ask for them.

Environment variables store data about a system’s environment so the system knows where to look for certain information. The PATH variable is one of the most well-known environment variables since it exists on Windows, Mac, and Linux machines and does a fairly user-facing job on all. Its actual form is just a text string containing a list of directory paths that the system will search every time you request a program.

Windows Path Python Example

This is a bit like adding a desktop shortcut to your command line. Instead of entering “C:UsersusernameAppDataLocalProgramsPythonPython38-32python.exe” to launch Python, you can add the folder containing the file to the PATH variable and just type “python” to launch it in the future. Do that for any program you like, whether it launches a GUI (like Notepad) or works in the command line interface (like Python).

Windows Path Charmap Launch

On Windows, PATH (capitalized by convention only, since Windows’ NTFS file system is not case-sensitive) points by default to the “C:Windows” and “C:Windowssystem32” directories.

If you type charmap into the command line, you’ll get a massive list of Unicode characters you can copy and use, for example. “notepad” runs Notepad, “msinfo32” gets you a list of your computer’s specs, and so on.

These programs can also be launched with the GUI. But if you’re already working in the command line, launching programs just by typing their names is a lot easier. This is especially true if you’re trying to launch a program that will open and run inside the command line interface, like Python or Node.js.

How do I edit the PATH variable?

The Windows GUI is pretty straightforward, so it’s probably the best way for most people to edit PATH.

Using the Windows GUI

1. Open “System Properties” and go to the “Advanced” tab. The easiest way to do this is by typing environment variable into your Windows Search bar and clicking “Edit the system environment variables.”

Windows Path System Properties Search

Alternatively, you can go to “Control Panel -> System and Security -> System” and click “Advanced system settings;” type sysdm.cpl into the Run command; or right-click “This PC,” select “Properties,” and click “Advanced system settings.” They all go to the same place.

2. Once you’re in the “Advanced” tab, click “Environment Variables … ”

Windows Path System Properties Advanced

3. The top box contains user variables, meaning any edits will only apply to your account. If you have multiple accounts on one machine and want the changes to affect everyone, edit the bottom box containing system variables instead.

Windows Path Environment Variables

4. Select the user or system Path variable (don’t let the title-case throw you; PATH and Path are the same in Windows) you want to edit and click the “Edit … ” button below the box.

Windows Path Edit Environment Variable

5. If you already have the path to the folder you want to add, just click “New” and paste in the full path (not directly to the executable, just to the folder containing it). I’m pasting in the path to my NodeJS directory so I can use JavaScript in the command line.

Windows Path Edit Environment Variable New

6. If you’d rather browse to the folder and select it manually, use the “Browse” button to navigate to the folder where your executable is located and hit the “OK” button when you’re there.

Windows Path Edit Environment Variables Browse Node

7. If you want your program to launch slightly faster, you can use the “Move Up” and “Move Down” buttons to put its folder closer to the top so it’ll pop up more quickly in the directory search.

8. Open a new command-prompt window and test your program by typing in the name of the executable you want to launch. It won’t work in the current window since it’s still using the old PATH variable.

Edit PATH Variables Using Command Prompt

The Windows 10 GUI is very usable and should meet most peoples’ needs, but if you need to use the command line to set PATH and environment variables, you can do that too.

1. Open the command prompt as administrator, then enter the command set.

2. Scroll through the list of paths, then find the variable you want to edit. The variable name is the part before the ‘=’ sign, the variable value is the part after, which you will rename to the directory you want it point to.

What Is Windows Path Edit Environment Variable Cmd 1

3. With that in mind, to edit the PATH, enter the following command:

setx variable name "variable value"
Windows Path Cmd Setx

You can use the following code to set your System PATH from the Command Prompt. (Run as administrator.) To use it to set your User PATH , just remove the /M.

setx /M PATH "%PATH%;<path-to-executable-folder>"

If you have problems, it’s a good idea to read through the known issues with and fixes for the setx command truncating the variable to 1024 characters or otherwise altering the variables. Definitely back up both your user and your system path variables first.

Frequent Asked Questions

1. Why would I need to edit PATH?

Chances are, if you’re reading this, you’ve run into something that requires you to add it to the PATH variable, so that’s probably what you should do. If you just want to add something to your PATH for easier access, though, that’s also fine. Just make sure it doesn’t interfere with the higher-priority programs.

2. Is there a Windows PATH length limit?

Yes, there is. So PATH-changing enthusiasts beware that the limit is 260 characters.

3. Can I disable the Windows PATH length limit?

Yes you can! Go to the Registry Editor, then within that navigate to:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlFileSystem

In the right-side pane, double-click the entry called “LongPathsEnabled”, then change the “Value data” value from 0 to 1. Click OK, and you’re good to go.

What Is Windows Path Disable Length Limit

Ready to keep digging beneath the Windows bonnet? Then head over to our favorite Windows registry hacks. Or for something a little lighter, check out our list of the best Windows 10 themes.

Robert Zak

Robert Zak

Content Manager at Make Tech Easier. Enjoys Android, Windows, and tinkering with retro console emulation to breaking point.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Понравилась статья? Поделить с друзьями:
  • How to add environment variables windows
  • How to add directory to path windows
  • How to add chromedriver to path windows
  • How to add app to startup windows 10
  • How to add an exclusion to windows defender