3

I am following a tutorial to setup Apache Storm. (That's just for context -- it doesn't really matter for my error.)

So it tells me to set some environment variables, specifically %JAVA_HOME% and %STORM_HOME% as C:\Java\jdk1.8.0_60\ and C:\storm-0.9.1-incubating-SNAPSHOT-12182013\, respectively. I've never done this sort of thing before, so I looked up how to do this and I ran:

C:\>setx %JAVA_HOME% C:\JAVA\jdk1.8.0_60\

and it gave: SUCCESS: Specified value was saved.

Then I did:

C:\>setx %STORM_HOME% C:\storm-0.9.1-incubating-SNAPSHOT-12182013\

and it gave the same thing: SUCCESS: Specified value was saved.

Then the tutorial says to add %STORM_HOME%\bin;%JAVA_HOME%\bin;C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\; to PATH. I entered C:\>PATH to see what it currently is and it gave:

PATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

So I thought I could add to it by doing

C:\>setx PATH C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;%STORM_HOME%\bin;%JAVA_HOME%\bin;C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\; 

In other words, I just tried calling setx on PATH and I set it to what it currently is and with the stuff the tutorial says appended to the end. It gave SUCCESS: Specified value was saved. However, when I enter:

C:\>PATH

it returns what it was originally (the stuff I tried appending is not there). I tried another method. I ran

C:\>PATH=%PATH%;%STORM_HOME%\bin;%JAVA_HOME%\bin;C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;

Then when I entered C:\>PATH it returned the full PATH with the stuff I wanted to append appended.

The problem I now face is using these variables. When I enter

C:\>cd %STORM_HOME%

it says The system cannot find the path specified. I tried restarting my computer but PATH got reset and I still got the same error.

2 Answers 2

3

@DavidPostill is correct, but doesn't actually resolve your problem. The actual answer is much simpler: Command Prompt, like any program, receives its environment variable at startup. When you set a persistent environment variable (either per-user or system-wide), you are changing the registry values that determine the environment variables for future processes. You aren't actually changing any environment variables in the current process at all!

From the SETX help documentation (setx /?):

 2) On a local system, variables created or modified by this tool
    will be available in future command windows but not in the
    current CMD.exe command window.

There are two ways to address this. The simple one is, as the documentation indicates, start a new instance of CMD. That's easy enough, but then you won't have your command history, etc. The more complicated one is to set the local environment variables (use the set command). The best way to do this is actually to use set first, and then invoke setx using the current environment variables. Here's an example, from what you are doing above:

REM Set the local version of JAVA_HOME
set JAVA_HOME=C:\JAVA\jdk1.8.0_60\
REM Set the local version of STORM_HOME
set STORM_HOME=C:\storm-0.9.1-incubating-SNAPSHOT-12182013\
REM Append the new values to PATH
set PATH=%PATH%;%STORM_HOME%\bin;%JAVA_HOME%\bin;C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;
REM Do whatever checks you want to do to confirm that those are set correctly
cd %STORM_HOME%
REM Now, save the current (local) values of the environment variables
REM to persistent storage (registry)
setx JAVA_HOME %JAVA_HOME%
setx STORM_HOME %STORM_HOME%
setx PATH %PATH%

Note the use of % characters. You use them when you went to expand an environment variable, not when you want to refer to one. The setx lines above are processed as "Set the user-wide environment variable JAVA_HOME to this process' current local value of JAVA_HOME", which is equivalent to saying "Set the persistent environment variable JAVA_HOME to C:\JAVA\jdk1.8.0_60\" because that's what %JAVA_HOME% expands to in the current process.

1
  • Thank you for this! I understand it a lot better now, and it worked too :) Commented Sep 19, 2015 at 20:00
1

Why didn't SETX update my PATH

setx PATH C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;%STORM_HOME%\bin;%JAVA_HOME%\bin;C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;

Your setx syntax is wrong:

  • Put the quotes " around the second parameter (the 'value').

    The second parameter should be quoted if it contains spaces and %PATH% almost always contains spaces.

You should be using:

setx PATH "%PATH%;%STORM_HOME%\bin;%JAVA_HOME%\bin"

Or:

setx PATH "%STORM_HOME%\bin;%JAVA_HOME%\bin;%PATH%"

Syntax

SETX [/s Computer [Credentials]] Variable Value [/m]

SETX [/s Computer [Credentials]] [Variable] /k RegistryPath [/m]

SETX [/s Computer [Credentials]] /f FileName {[Variable] {/a L,T | /r oL,oT "SearchString"} [/m] | /x} [/d Delimiters]

Source setx


Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • setx - Set environment variables permanently, SETX can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU).
1
  • Very interesting. I appreciate the help! With this and CBHacking's help above I was able to figure it out. I would +1 if I could! Commented Sep 19, 2015 at 20:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.