← Other topics

PATH Variable (Windows)

Video Notes

When you run a command for a program in command line, it looks for the corresponding executable files using the directories listed in your computer or server’s PATH variable. The PATH variable is one of many Environment Variables your system uses.

Given this, when you add a new command line program to your computer, you have to add its directory to your PATH variable.

In the following instructions, I will demonstrate this process by adding the PHP executable that comes with XAMPP to my PATH, but the steps would be the same for whatever executable you’re trying to configure.

When working in command line I will use Git Bash. The commands I use will vary if you’re using a non-Unix based command line program.

Current paths

To begin, use this command to see what your PATH variable is currently set to:

echo $PATH

Example output:

/c/Users/Susan/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Susan/bin:/c/Program Files (x86)/Parallels/Parallels Tools/Applications:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cmd:/c/WINDOWS/System32/OpenSSH:/c/Users/Susan/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/Susan/AppData/Local/Microsoft/WindowsApps:/usr/bin/vendor_perl:/usr/bin/core_perl

Note that each path is separated by a colon. For a more legible view, the following command will output the same results with each path shown on its own line:

tr ':' '\n' <<< $PATH
/c/Users/Susan/bin
/mingw64/bin
/usr/local/bin
/usr/bin
/bin
/mingw64/bin
/usr/bin
/c/Users/Susan/bin
/c/Program Files (x86)/Parallels/Parallels Tools/Applications
/c/WINDOWS/system32
/c/WINDOWS
/c/WINDOWS/System32/Wbem
/c/WINDOWS/System32/WindowsPowerShell/v1.0
/cmd
/c/WINDOWS/System32/OpenSSH
/c/Users/Susan/AppData/Local/Programs/Microsoft VS Code/bin
/c/Users/Susan/AppData/Local/Microsoft/WindowsApps
/usr/bin/vendor_perl
/usr/bin/core_perl

Adding paths

To edit PATH variables in Windows first run sysdm.cpl in your search bar to open your computer’s Control Panel:

Then, from the Advanced tab choose Environment Variables:

Under User variables find Path, select it, and click Edit:

At the end, including the path to whatever executable you’re adding (in this example that’s XAMPP’s PHP located at c:\xampp\php\). Make sure your path ends with a trailing \. Ok/Save your changes when done.

Make the changes take effect

Close and restart your command line program. This step is important - If you don’t do this, your changes won’t take effect.

Test it

To test that it worked you can use the which command to ensure it’s resolving your new command to the correct path:

> which php
/c/xampp/php/php

You can also invoke your command, for example:

> php --version
PHP 8.1.1 (cli) (built: Dec 21 2021 08:45:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
If this info helped you out, toss a coin in the tip jar?
← Other topics