How to set Java Home & How to add Java Path on Ubuntu

We need to use the terminal to define JAVA_HOME environment variable and set Java path on your Linux. Use shortcut Alt+Ctrl+T to launch the command line.

How to set Java Home?

Edit ~/bashrc:

gedit ~/.bashrc

and add JAVA_HOME variable to the end of file:

export JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/"

Note: don’t forget to set your path to Java folder!

How to set Java path?

Add to the end of bashrc the following:

export PATH=$PATH:$JAVA_HOME/bin/

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

source ~/.bashrc

How to check JAVA_HOME?

Type “echo $JAVA_HOME” in the terminal.

Success output should looks like that:

/usr/lib/jvm/java-8-oracle/jre/bin

Congratulations! Java Home environment variable and Java path are set on your Ubuntu environment and ready to use.

Leave a Comment