Home Ā» How to Install Latest Java and Set JAVA_HOME on Ubuntu

How to Install Latest Java and Set JAVA_HOME on Ubuntu

by Imran Shaikh
75 views
How to Install Latest Java and Set JAVA_HOME on Ubuntu

Hey, Tea lovers! In this post, we will have a look at how we can easily install the latest Java or JDK on the Ubuntu system. It will be a very quick and small post.

Before You Start

I will be installing Open JDK, and I will show the installation for JDK 8, JDK 11, and JDK 14 on ubuntu. For the Windows user, I have already written a post on “Install Latest or Any Java Version in 3 Simple Steps: Windows“.

As you might know, for us developers to develop the Java programs, we need JDK and not only JRE. If you install JRE then you can only run the Java programs and not compile them. So keep in mind, whenever I say Java, in this post, I will be referring to the JDK.

Before installing make sure to update the repositories with the following.

sudo apt-get update && sudo apt-get upgrade -y

You can follow me on social @coderstea on TwitterLinkedinFacebook, or Instagram. We will be sharing the high-quality videos about programming on our Youtube channel very soon. You can also publish your own post on CodersTea.com, just share your thought on Contact Us.


Install Java 8 on Ubuntu

To install Java 8 in Ubuntu, you need to run the following command.

sudo apt-get install openjdk-8-jdk

It will ask for confirmation, simply type press y and hit enter. Then wait for few minutes until it gets installed.

How to get the JAVA_HOME path for Java 8 is described in the last block of this post. Click here to jump to the block.

Install Java 11 on Ubuntu

For Java 11 the process is the same. Simply change the version to 11. And you will get the following command to install Java 11 on Ubuntu.

sudo apt-get install openjdk-11-jdk

Then same confirmation and waiting time.

The JAVA_HOME path for Java 11 is shown in the last block of this post. Click here to jump to the block.

Install Java 14 in Ubuntu

Until now, you guys must have realized that you simply need to change the number of in the command openjdk-<version-number>_jdk, and you can install the desired version. But just for the sake of SEO, let me add one more block for Java 14 as well. The command to install Java 14 on Ubuntu is as follows. #

sudo apt-get install openjdk-11-jdk

See the next block to see how to get the JAVA_HOME path for Java 14.

Set Java Home Variable JAVA_HOME in Ubuntu

After installing Java on any machine, you must set up the JAVA_HOME. Without JAVA_HOME many of the tools or packages will not work, such as Maven. To set up the path you need to figure out the path of the installed Java on your machine.

Get the List of Installed Java in your Ubuntu Machine

The best way to see the installed Java path is to use the following command.

update-java-alternatives --list

This command will show you the list of installed Java in your Ubuntu machine. For me I have installed both Java 11 and Java 8, so I will be seeing two outputs as follows.

java-1.11.0-openjdk-amd64 1111  /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64  1081  /usr/lib/jvm/java-1.8.0-openjdk-amd64

The first column indicated the java version and the 3rd column is the respected path for that Java. So for Java 11, it installed on /usr/lib/jvm/java-1.11.0-openjdk-amd64 and For java 8 it got installed on /usr/lib/jvm/java-1.8.0-openjdk-amd64.

Set up JAVA_HOME

Got to Terminal and type the following command.

gedit ~/.bashrc

It will open the .bashrc file in the text editor. Go to the end of the file and type the following command. I will be using path of Java 11 but you can use whatever Java you have installed in your ubuntu.

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

Replace the path after = with your desired Java path.

Conclusion

That’s it for this post. We looked at how we can easily install and set up any version of Java. I hope you liked the post. I will be soon publishing one for the centos as well, so stay connected with us on social media @coderstea on TwitterLinkedin, Facebook, or Instagram.

See you in the next post.

HAKUNA MATATA!!!

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy