How To Set Java Path & JAVA_HOME in Windows 10, MacOS & Ubuntu

I’ll explain to you how to set Java path variable on Windows, MacOS, and Ubuntu (Linux).

I’ve prepared awesome examples how to set Java Home via command prompt and GUI (Windows) as well.

I’ll show you how to check Java version and verify Java Home variable.

Setup Java Path on Windows 10

Open Start menu and search for Advanced System Settings:

advanced system settings in start menu on Windows 10

Launch View advanced system settings:

system properties on Windows 10

Go to Environment Variables:

system variables on Windows 10

Add new system variable with a name JAVA_HOME and value – your path to Java, in my case, it’s C:\Program Files\Java\jre-9.0.4 and press “OK”.

new Java home system variable on Windows 10

Then press “Edit…” for Path system variable and add new path %JAVA_HOME%\bin or change already existing path to Java.

set Java path variable on Windows 10

We set Java home and Java path variables, let’s check is it really work.

Double-click on Start menu – Runcmd.

We can check Java home variable by typing  echo %JAVA_HOME%.

And we can verify the version of Java as well  java -version.

If everything is OK your output should be more or less the same as mine.

check Java version on Windows 10

Setup Java Path on MacOS

Open Launchpad, search for Terminal and launch it.

Execute  echo $JAVA_HOME to check is Java Home already set or not.

If an output is empty – you need to set $JAVA_HOME variable.

Edit .bash_profile:

and add to the end:

${/usr/libexec/java_home} is a symlink for current Java.

Press Ctrl+X to exit and “Y” to save your changes.

Now we need to recompile .bash_profile:

Let’s execute echo $JAVA_HOME once again to check a value of Java Home variable.

The output should be something like that:

So we set JDK path by adding it to bash_profile file on MacOS.

Setup Java Path on Ubuntu

Open command line using shortcut Alt+Ctrl+T.

Let’s check is Java Home variable set or not by executing  echo $JAVA_HOME.

If an output is empty – Java Home is not set and you need to set it.

You need to edit ~/bashrc:

and export JAVA_HOME variable:

Edit path to Java if it’s in a different folder then mine.

Then you need to add Java path variable:

Recompile bashrc file to apply changes otherwise, it will be visible only after reboot.

and check Java Home variable again  echo $JAVA_HOME.

Output is:

Java home and Java path variables are set on your Ubuntu environment and ready to use.

Scroll Up