Windows 7 environment variable not working in path

112,642

Solution 1

I had exactly the same problem, to solve it, you can do one of two things:

  • Put all variables in System Variables instead of User and add the ones you want to PATH

Or

  • Put all variables in User Variables, and create or edit the PATH variables in User Variable, not In System. The Path variables in System don't expand the User Variables.

If the above are all correct, but the problem is still present, you need to check the system Registry, in HKEY_CURRENT_USER\Environment, to make sure the "PATH" key type is REG_EXPAND_SZ (not REG_SZ).

Solution 2

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\

Solution 3

My issue turned out to be embarrassingly simple:

Restart command prompt and the new variables should update

Solution 4

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.

Solution 5

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

Share:
112,642

Related videos on Youtube

jiminssy
Author by

jiminssy

Updated on July 09, 2022

Comments

  • jiminssy
    jiminssy almost 2 years

    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?

    • calebds
      calebds over 12 years
      What does echo %PATH% output?
    • hknust
      hknust over 9 years
      I had the same problem and found it to be a path length issue. I created new environment variables, P86 and P64, to replace all occurrences of "C:\Program Files (x86)" and "C:\Program Files" references in the existing PATH variable. The new path (System + User) is currently 2754 characters after expansion of the new variables. I read in similar threads that the theoretical limit is 32KB but apparently that is not the practical limit.
  • Pixel
    Pixel over 10 years
    This worked for me! Had no idea about this whatsoever.
  • Rahmathullah M
    Rahmathullah M about 9 years
    Hi @pcmind, mine is set to REG_SZ, what should i do now?
  • Zhe Hu
    Zhe Hu almost 9 years
    make a copy of the value of "PATH" key (with type REG_SZ), delete "PATH" key, create a new key with type REG_EXPAND_SZ and paste in the old value. restart computer.
  • Saman
    Saman over 8 years
    This could be an option . However, the suggestion below makes more sense. If there is no space kind of problem, even if you define in both user and system level, it should work.
  • Venkateswara Rao
    Venkateswara Rao almost 8 years
    There is alternative way by going to Control Panel --> All Control Panel Items --> User Accounts and then click on 'Change my environment variables' in the left navigation.. but somehow it is not working in Windows 7 and 10 . Till Microsoft address that we can use above way of setx.
  • aguertin
    aguertin almost 8 years
    Do not ignore this answer; 9 times out of 10 this is the problem.
  • Alex
    Alex over 7 years
    I can see that I have spaces (from cmd and python) but I dont know how to get rid of them. I've been banging my head against the wall for like 3 hours now!
  • gt124
    gt124 over 7 years
    Windows 10 has the same issue and fix stated by pcmind.
  • TinkerTenorSoftwareGuy
    TinkerTenorSoftwareGuy over 7 years
    This answer saved me tons of frustration and explained some serious discrepancies on my path variable: The Path variables in System don't expand the User Variables.
  • dyasta
    dyasta over 6 years
    It CAN cause errors for a small minority of users. I am investigating something similar, but your conclusion is incorrect here. Most users have paths appended or prepended with spaces w/o issue, the semicolon is a fine delimiter that means no quotes required, but we have found that for some users this can be true. Why is that some small minority of users are affected in this way, but not others? Unknown as of this time. That is why that app added itself as such, it was not some simple omission.
  • Silviu Burcea
    Silviu Burcea over 6 years
    Not true. I have them in SYSTEM variables. For me, it was the spaces in the paths, like C:\Program Files, who caused the OP problem.
  • Mehdi
    Mehdi over 6 years
    Microsoft do a lot of efforts to create problems
  • Fernando Vieira
    Fernando Vieira over 5 years
    the same happens with WIN10 too. The REG_SZ trick solved it! Thanks!
  • Akaisteph7
    Akaisteph7 almost 5 years
    This was my issue. Thanks!
  • Razzle
    Razzle about 4 years
    For example I just noticed that my path included the literal text %NVM_HOME% even though this is a defined variable.. this was fixed after I noticed there was a %CHOCOLATEY_HOME% immediately prior, left there after I uninstalled chocolatey, so there was no definition for that variable. I removed the chocolatey variable from the path, and then the NVM_HOME variable got correctly replaced with its value. It's surprising a basic issue like this remains in windows. Makes me wonder what else is broken...
  • fahimalizain
    fahimalizain almost 4 years
    This happened in Win10 with me, a system restart was necessary after changing REG_SZ --> REG_EXPAND_SZ
  • yeah_well
    yeah_well almost 4 years
    This happens because each process gets a set of environment variable and when you quit and start cmd ,the process will get new path variables
  • Andrey
    Andrey about 3 years
    sometimes it doesn't help. In my case - C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Scripts. It gives error anyway