Setting environment variables on Windows differs a little bit more than setting it on Linux. There are two areas where this can be set; each with their own pros and cons:
Let’s look at all three methods in this post.
Setting Environment Variables for Single Use Only
Pros: good for running the environment variable for sparing use only (such as Maven deployment)
Cons: will be cleared once the command line window is closed; tedious to re-setup
- Run command line.
- Run the following command:
set %VARIABLE_NAME%=%PATH%(replace%VARIABLE_NAME%with the variable name you would like to set, and%PATH%with the relevant path).
Examples of usage:
JAVA_HOMEset JAVA_HOME=C:\Program Files\Java\jdk1.6.0_38M2_HOMEset M2_HOME=C:\devel\maven-2.2.1- Run
echocommand to check results:%JAVA_HOME%echo %JAVA_HOME% C:\Program Files\Java\jdk1.6.0_38%M2_HOME%echo %M2_HOME% C:\devel\maven-2.2.1
Setting Environment Variables for All Users
Pros: good to limit certain users to execute certain enviroment variables.
Cons: if other users would like have the same environment variables, they would need to set this by themselves.
- Run command line.
- Run the following command:
setx %VARIABLE_NAME% "%PATH%"(replace%VARIABLE_NAME%with the variable name you would like to set, and%PATH%with the relevant path).
Examples of usage:
JAVA_HOMEsetx JAVA_HOME "C:\Program Files\Java\jdk1.6.0_38"M2_HOMEsetx M2_HOME "C:\devel\maven-2.2.1"- Run
echocommand to check results:%JAVA_HOME%echo %JAVA_HOME% C:\Program Files\Java\jdk1.6.0_38%M2_HOME%echo %M2_HOME% C:\devel\maven-2.2.1
To set the environment path, you can do so by right-clicking the My Computer icon > Properties > Advanced > Environment Variables and adding the path in the PATH variable under System Variables:








