[Windows] How to Set Environment Variables and Path

windows7

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

  1. Run command line.
  2. 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_HOME
                        set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_38
                    
  • M2_HOME
                        set M2_HOME=C:\devel\maven-2.2.1
                    
  • Run echo command 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.

  1. Run command line.
  2. 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_HOME
                        setx JAVA_HOME "C:\Program Files\Java\jdk1.6.0_38"
                    
  • M2_HOME
                        setx M2_HOME "C:\devel\maven-2.2.1"
                    
  • Run echo command 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:

Image 1: My Computer's Properties window

Image 1: My Computer’s Properties window


Image 2: Enviroment Variables window

Image 2: Enviroment Variables window


Image 3: An example to set JAVA's PATH variable.

Image 3: An example to set JAVA’s PATH variable.


Was That a Good Read? Rate It!

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Add a Comment

Your email address will not be published. Required fields are marked *

CommentLuv badge