How to set Java environment path $JAVA_HOME in Ubuntu

Java  based environment requires java installed on your system. Please check post how to install Java on ubuntu for installation. Sometimes even after installation of Java, environment variables are not set and this might have adverse impact on Java based software.

  1. Check if Java is installed

You can check if Java is install ed by following command

$ java --version
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04, mixed mode, sharing)
  1. Check if $JAVA_HOME variable is set
$ echo $JAVA_HOME

If it returns blank,it means its not set up.

  1. Check Java directory.

Java is installed in directory /usr/lib/jvm in Ubuntu

$cd /usr/lib/jvm
:/usr/lib/jvm$ ls -la
total 16
drwxr-xr-x   3 root root 4096 Dec 19 23:22 .
drwxr-xr-x 133 root root 4096 Dec 25 23:36 ..
lrwxrwxrwx   1 root root   25 Feb 20  2019 default-java -> java-1.11.0-openjdk-amd64
lrwxrwxrwx   1 root root   21 Jul 18 23:51 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
-rw-r--r--   1 root root 1994 Oct 17 03:31 .java-1.11.0-openjdk-amd64.jinfo
drwxr-xr-x   7 root root 4096 Dec 19 23:22 java-11-openjdk-amd
  1. Setting up the $JAVA_HOME value

Open terminal and type following

$export JAVA_HOME=/usr/java/java-1.11.0-openjdk-amd64

You need to replace java-1.11.0-openjdk-amd64 with <your java version>

Now check the content of $JAVA_HOME by typing below

$$ echo $JAVA_HOME
/usr/java/java-1.11.0-openjdk-amd6

Variable $JAVA_HOME is case sensitive so make sure you check and set correct variable.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.