OpenJDK is an open source version of Java Development Kit and is available on most Linux package repositories. Sadly, the version is quite outdated since Java programs today are compiled for the latest Java Environment (which is now version 10), the package found on most Linux repositories is still in previous stable release ie., v1.8. This article will guide you on how to install the latest OpenJDK on your Linux computer, and how to set its environment variables so you can start right away with your Java project.
To download OpenJDK head over to the website jdk
and click on the “Ready for use” link.
Under Downloads heading, select the Linux tar.gz link. Now, this is nothing like the deb or rpm file you normally download to install a Linux program on your computer. However, it has an advantage and that is such tarballs are reliable for distributing Linux software across multiple Linux distributions since it would work on almost all of them.
The only disadvantage is you would have to manually access the website and download OpenJDK every time a new Java version is released. But fret not, you still enjoy the same stable version for a period of more than six months. So it’s not going to be rapidly updated like Firefox and Google Chrome does.
If you are cautious of what you download from the Internet, make sure you click that sha256 link and verify with the Linux tarball you just downloaded.
Now it’s time to unpack the archive file and install OpenJDK on your computer. There are two ways to extract the tarball:
- Using a File manager program or
- Using a terminal program
Since the graphical method is easier on most modern Desktop Environments, I’ll proceed ahead with the File manager program. Browse to the Downloads directory/library and right click the OpenJDK tarball file, you’ll notice Extract (Extract to or Extract here) options. Extract the file to your home root directory, not on the Downloads directory.
Take note that, the contents are inside the folder named “jdk-10.0.1″. So if by mistake the tarball was extracted to Downloads directory, move the folder ie., jdk-10.0.1, to your home directory. And that’s it! You’ve successfully installed OpenJDK on your computer. Now all you have to do is set up its environment variables.
âSince we’re installing the OpenJDK program on one specific user account, we’ll set up environment variables as local (only accessible from your user account). Otherwise, if you intended other users to access the program you’d have to move the jdk folder to another partition and mount the partition automatically when your computer boots up by editing the /etc/fstab file.
Edit the file ~/.profile using one of your favorite text editors and add the below commands on the last line.
You can add descriptive comments to remind yourself of its purpose.
Using sudo, create a file named openjdk.sh on /etc/profile.d/ directory and enter the below commands to the new file.
After you’re done, log out from your account and log back in so the environment variables get updated. Then launch a terminal program and test the java version to make sure it’s ready to be used.
To uninstall OpenJDK, simply delete its folder and undo the environment variables setup by removing those three export lines. However, if you set it as system-wide delete that openjdk.sh file too.