≡ Menu

Set path from command line

Users can run an executable from windows command prompt either by giving the absolute path of the file or just by the executable file name. In the latter case, Windows searches for the executable in a list of folders which is configured in environment variables. These environment variables are as below.

1. System path
2. User path

The values of these variables can be checked in system properties( Run sysdm.cpl from Run or computer properties). Initially user specific path environment variable will be empty. Users can add paths of the directories having executables to this variable. Administrators can modify the system path environment variable also.

How to set path from command line?

In Vista, Windows 7 and Windows 8 we can set path from command line  using ‘setx’ command.

setx path "%path%;c:\directoryPath"

For example, to add c:\dir1\dir2 to the path variable, we can run the below command.

setx path "%path%;c:\dir1\dir2"

Alternative way is to use Windows resource kit tools ‘pathman.exe‘. Using this command we can even remove a directory from path variable. See download windows resource kit tools. This works for Windows 7 also.

Add directory to system path environment variable:

Open administrator command prompt
Run  the below command

pathman /as directoryPath

Remove path from system path environment variable:
Run the below command from elevated command prompt

pathman /rs directoryPath

Setting user path environment variable

For user environment varlables, admin privileges are not required. We can run the below command to add a directory to user path environment variable.

pathman /au directoryPath

To remove a directory from user path, you can run the below command.

pathman /ru directoryPath

Default option is not allowed more than ‘2’ time(s)

You get this error if you have not enclosed ‘path’ in double quotes. See the below example for setting the path of firefox.

C:\Users\>setx path %path%;"c:\Program Files (x86)\Mozilla Firefox\"
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

Now if you move %path% to be in the double quotes

C:\Users\>setx path "%path%;c:\Program Files (x86)\Mozilla Firefox\"
SUCCESS: Specified value was saved.
C:\Users\>
23 comments… add one
  • Jo

    Could a context entry be created for folders, perhaps an extended one… to add to path?

    what about a multi-verb option, like copy as path?

  • Johny Why

    hi, when i use setx at an administrator command line, it creates a USER variable, NOT the SYSTEM variable. What am i doing wrong? How do i change the SYSTEM path at command prompt? -thx

  • Sebastian Bärgård

    Johny Why
    Answer: Try add the parameter /M

  • Nuno

    Hi, is there a way I can add an extra variable instead on deleting the currently one and put a new Variable on the Path.

    I used the command setx /M “c:\Options”, and what it does is delete the current one and then puts that one there, all I want is to add the new variable to the current one. -thx

    • admin

      Nuno, pathman described above does exactly that. You can download the resource tools kit and get it.

    • nalimleinad

      setx path “%path%;C:\yourFolder”

  • Nir

    To set path for java & javac, can I add the paths to PATH or do I need to create the environment variable JAVA_HOME. I don’t have this defined, but windows does not seem to be able to find java binaries on my system.

    • admin

      You can directly add the folder to PATH. No need to define JAVA_HOME. However, adding JAVA_HOME separately avoids cluttering and helps to easily understand what is added.

  • johny why

    hello, can someone plz explain this result? After setting path, it did not change. This was run from an Administrator command-line:

    C:\Windows\system32>setx path “C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin”

    SUCCESS: Specified value was saved.

    C:\Windows\system32>path
    PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin;D:\Program Files (x86)\metapad36;D:\Program Files (x86)\metapad36″ /M

    thx!

  • Bill

    Why won’t this work?

    SET EPO = D:\Program Files (x86)\McAfee\ePolicy Orchestrator
    PATH = %PATH%;%EPO%\jre\bin;%EPO%\apache2\bin

  • sayed

    In windows 10 set path %path%; not working. it’s work like :
    setx “%path%;C:\Program Files\CodeBlocks\MinGW\bin”

  • Vaishnavi

    By unfortunately I deleted my system default path. How could I able to find my system path?

  • Felipe

    nice article!

  • andy

    Unfortunately I deleted several files with unremembered path names. This article was useful

  • Karl Tan

    The following used to work for me when I am in MSDOS environment. Lately I get error messages such as INCLUDE not found. Why is this so?

    Used to work
    SET PLL =c:\CL5\PLL
    SET PLT =c:\CL5\PLL
    SET INCLUDE =c:\CL5\INCLUDE
    SET PRG =c:\IMS\PRG
    SET LIB =c:\CL5\LIB
    SET OBJ =c:\CL5\OBJ
    PATH =c:\IMS\EXE;\CL5\BIN;\CL5\NG;\CL5\PLL

  • non

    pathman is one of many tools of the Windows Server 2003 Resource Kit Tools

    Note: The Windows Server 2003 Resource Kit Tools are not supported on 64-bit platforms.

  • Ben

    Huh.
    When I did that on Windows 10 v1903, using setx, it replaced the USER scope paths with the SYSTEM scope paths.
    Now I’m not sure what was in the old user path.
    So, uh… Be careful out there.
    And if anyone has a solution how to avoid that, please let me know
    Thanks

  • murali

    how to del all my path and set new path.my sql iam not getting connected to XAMPP.

  • Thank you. Just what I needed.

  • shobhitjuyal

    Thanks man !! you save my life

  • pathman is one of many tools of the Windows Server 2003 Resource Kit Tools

    Note: The Windows Server 2003 Resource Kit Tools are not supported on 64-bit platforms….

  • kishan

    The above method is working fine, actually I used this command inside my .bat file but the is it does add the path variable but then in executing that application on cmd it still does not work but then i opened environment variables and just went up to path and that directory was already there then I just clicked ok a couple of time and then everything worked fine on cmd.
    so how can i make sure that I won’t have to do this whole manual opening thing.
    thank you.

  • lulliS

    pathman is one of many tools of the Windows Server 2003 Resource Kit Tools Note: The Windows Server 2003 Resource Kit Tools are not supported on 64-bit platforms

Leave a Comment