Skip to content

How to setup Java Environment Variables

Windows

Download and Install Java

  • Download latest version or your required version Java (Java Oracle , OpenJDK)
  • Install on your system

Set JAVA_HOME and PATH

  • Right-click on This PC (or My Computer) and select Properties.
  • Click on Advanced system settings.
  • In the System Properties window, click Environment Variables.

Add JAVA_HOME:

  • Under System variables, click New.
  • Set Variable name as JAVA_HOME.
  • Set Variable value as the path where Java is installed. For example: C:\Program Files\Java\jdk-XX(replace XX with the version number).

Update PATH:

  • Under System variables, find the Path variable, select it, and click Edit.
  • Click New and add %JAVA_HOME%\bin

Verify Setup:

  • Open a new command prompt and type

java -version
javac -version
echo %JAVA_HOME%
- You should see the Java version and the JAVA_HOME path.

Windows

  • Right click on the 'My Computer' icon on your desktop and select 'Properties'.
  • Click the 'Advanced' tab.
  • Click the 'Environment Variables' button.
  • Click 'New'.
  • In the 'Variable name' field, enter 'JAVA_HOME'.
  • In the 'Variable value' field, enter the directory (including its full path) where you installed the JDK.
  • Restart the computer.

Linux

For your current user:

  • Open up a shell / terminal window
  • vi ~/.profile (replace vi with your favorite text editor)
  • Add export JAVA_HOME=/path/to/java/home/dir on its own line at the end of the file
  • Add export PATH=$JAVA_HOME/bin:$PATH on its own line immediately after
  • Save, and restart your shell
  • Running java -version should give you the desired results

For all users in the system:*

  • Open up a shell / terminal window
  • vi /etc/profile (replace vi with your favorite text editor)
  • Add export JAVA_HOME=/path/to/java/home/dir on its own line at the end of the file
  • Add export PATH=$JAVA_HOME/bin:$PATH on its own line immediately after
  • Save, and restart your shell
  • Running java -version should give you the desired results
  • If you are using a GUI, you may not need to open up the shell. Instead, you might be able to open the file directly in a graphical text editor.

Linux (Ubuntu or other distros):

Install Java

  • Install Java using the package manager for your Linux distribution:

    sudo apt update
    sudo apt install default-jdk
    
  • For specific versions (like OpenJDK 11), use:

sudo apt install openjdk-11-jdk

FAQ Setting JAVA_HOME

Comments