[variables] Windows 7 environment variable not working in path

I am trying to set up some path using environment variable. I added an environment variable "MAVEN_HOME" with the value "C:\maven". Then in the path I added "%MAVEN_HOME%\bin;...rest". When I type "echo $MAVEN_HOME%" I get the correct "C:\maven" printed on the screen. But when I type "mvn" which is a batch file in the "bin" directory, it can't find it.

So, I manually added the entire path in PATH. "C:\maven\bin;...rest" and it was able to find "mvn" and execute it.

Could someone help me what I did wrong?

This question is related to variables windows-7 path environment

The answer is


If there is any error at all in the PATH windows will silently disregard it. Things like having %PATH% or spaces between items in your path will break it. Be warned


I had this problem in Windows 10 and it seemed to be solved after I closed "explorer.exe" in the Task Manager.


Make sure both your System and User paths are set correctly.


To address this problem, I have used setx command which try to set user level variables.

I used below...

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_92"

setx PATH %JAVA_HOME%\bin

NOTE: Windows try to append provided variable value to existing variable value. So no need to give extra %PATH%... something like %JAVA_HOME%\bin;%PATH%


In my Windows 7.

// not working for me
D:\php\php-7.2.6-nts\php.exe

// works fine
D:\php\php-7.2.6-nts

My issue turned out to be embarrassingly simple:

Restart command prompt and the new variables should update


Also worth making sure you're using the command prompt as an administrator - the system lock on my work machine meant that the standard cmd just reported mvn could not be found when typing mvn --version

To use click 'start > all programs > accessories', right-click on 'command prompt' and select 'run as administrator'.


%M2% and %JAVA_HOME% need to be added to a PATH variable in the USER variables, not the SYSTEM variables.


Things like having %PATH% or spaces between items in your path will break it. Be warned.

Yes, windows paths that include spaces will cause errors. For example an application added this to the front of the system %PATH% variable definition:

C:\Program Files (x86)\WebEx\Productivity Tools;C:\Sybase\IQ-16_0\Bin64;

which caused all of the paths in %PATH% to not be set in the cmd window.

My solution is to demarcate the extended path variable in double quotes where needed:

"C:\Program Files (x86)\WebEx\Productivity Tools";C:\Sybase\IQ-16_0\Bin64;

The spaces are therefore ignored and the full path variable is parsed properly.


If the PATH value would be too long after your user's PATH variable has been concatenated onto the environment PATH variable, Windows will silently fail to concatenate the user PATH variable.

This can easily happen after new software is installed and adds something to PATH, thereby breaking existing installed software. Windows fail!

The best fix is to edit one of the PATH variables in the Control Panel and remove entries you don't need. Then open a new CMD window and see if all entries are shown in "echo %PATH%".


I had the same problem, I fixed it by removing PATHEXT from user variable. It must only exist in System variable with .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Also remove the variable from user to system and only include that path on user variable


Copy the value of path to notepad and check if this corresponds with the echo %path% in terminal window and make changes if needed. Then delete the old path value and paste the notepad value back in. I assume some invisible character entered there by some installation corrupted the path value.


Check if there is a space character between the previous path and the next:

Incorrect: c:\path1; c:\Maven\bin\; c:\path2\

Correct: c:\path1;c:\Maven\bin\;c:\path2\


Examples related to variables

When to create variables (memory management) How to print a Groovy variable in Jenkins? What does ${} (dollar sign and curly braces) mean in a string in Javascript? How to access global variables How to initialize a variable of date type in java? How to define a variable in a Dockerfile? Why does foo = filter(...) return a <filter object>, not a list? How can I pass variable to ansible playbook in the command line? How do I use this JavaScript variable in HTML? Static vs class functions/variables in Swift classes?

Examples related to windows-7

ng is not recognized as an internal or external command Why am I getting ImportError: No module named pip ' right after installing pip? How to Delete node_modules - Deep Nested Folder in Windows Telnet is not recognized as internal or external command Multiple -and -or in PowerShell Where-Object statement How do I set ANDROID_SDK_HOME environment variable? Run Batch File On Start-up Why isn't .ico file defined when setting window's icon? How to access shared folder without giving username and password Can't start hostednetwork

Examples related to path

Get Path from another app (WhatsApp) How to serve up images in Angular2? How to create multiple output paths in Webpack config Setting the correct PATH for Eclipse How to change the Jupyter start-up folder Setting up enviromental variables in Windows 10 to use java and javac How do I edit $PATH (.bash_profile) on OSX? Can't find SDK folder inside Android studio path, and SDK manager not opening Get the directory from a file path in java (android) Graphviz's executables are not found (Python 3.4)

Examples related to environment

Using Pip to install packages to Anaconda Environment How to generate .env file for laravel? Set windows environment variables with a batch file Setting up Eclipse with JRE Path Changing default shell in Linux How to find the path of the local git repository when I am possibly in a subdirectory Windows 7 environment variable not working in path Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'? Java system properties and environment variables Environment variables in Eclipse