Edit Article

Two Methods:For WindowsFor Linux

Do you want to set Java Home? The variable Java Home, generally written as JAVA_HOME, is set to the install path of Java. Learning how to set JAVA_HOME in Windows and Linux isn't hard to do.


Method 1 of 2: For Windows

  1. 1
    Assuming that the path for the Java Development Kit (JDK) during installation is not changed, it will be in a directory under C:\Program Files\Java. This path will have the JDK, let's assume it has jdk1.6.0_06. So the install path is C:\Program Files\Java\jdk1.6.0_06.
  2. 2
    Setting JAVA_HOME using "My Computer":
    1. Right click on the My Computer icon on your desktop and select properties
    2. Click the Advanced Tab
    3. Click the Environment Variables button
    4. Under System Variable, click New
    5. Enter the variable name as JAVA_HOME
    6. Enter the variable value as the install path "C:\Program Files\Java\jdk1.6.0_06"
    7. Click OK
    8. Click Apply Changes
    9. Restart the computer to make sure the changes are reflected.
  3. 3
    Setting JAVA_HOME using command prompt
    1. Open command prompt
    2. Type the following in the command prompt
      set JAVA_HOME = C:\Program Files\Java\jdk1.6.0_06
      and press enter
      The JAVA_HOME is set.

Method 2 of 2: For Linux

  1. 1
    To set the JAVA_HOME we use .bash_profile which is a start-up script. This particular file is used for commands which runs when the normal user logs in. The steps to set JAVA_HOME are:
    1. Login to your account and open .bash_profile file
      $ vi ~/.bash_profile
    2. If your path is set to /usr/java/jdk1.6.0_06/, set JAVA_HOME as follows:
      export JAVA_HOME=/usr/java/jdk1.6.0_06/
    3. Save and close the file. Logout and login back to see new changes, or type source ~/.bashrc



  • To check if JAVA_HOME is set in Windows type
    C:\> echo %JAVA_HOME%
    It will return the path set as follows :
    C:\Program Files\Java\jdk1.6.0_24
  • In Linux, .bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell. So updating the .bash_profile sets JAVA_HOME for a single user, for all users setup global config in /etc/profile OR /etc/bash.bashrc

  • To check if JAVA_HOME is set in Linux type
    $ echo $JAVA_HOME

Article Info

Categories: Java

In other languages:

Español: configurar Java Home, Italiano: Configurare Java Home, Português: Configurando o Java Home, Русский: установить Java Home, Deutsch: Java Home festlegen, Français: configurer Java Home

Thanks to all authors for creating a page that has been read 162,536 times.

Did this article help you?
Yes No