Skip to content

DevOps

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

java vs javaw vs javaws

java: Java application executor which is associated with a console to display output/errors

javaw: (Java windowed) application executor not associated with console. So no display of output/errors. It can be used to silently push the output/errors to text files. It is mostly used to launch GUI-based applications.

javaws: (Java web start) to download and run the distributed web applications. Again, no console is associated.

All are part of JRE and use the same JVM.

Difference between java, javaw, javaws and javac

https://javapapers.com/core-java/java-vs-javaw-vs-javaws/

What is the difference between 'java', 'javaw', and 'javaws'?

JDK VS JRE VS JVM

JDK is the development platform, while JRE is for execution. JVM is the foundation, or the heart of the Java programming language, and ensures the program's Java source code will be platform-agnostic. JVM is included in both JDK and JRE—Java programs won't run without it.