How to install Java development kit (JDK) on Linux

Last updated on September 11, 2020 by Dan Nanni

Question: I need to install Java Development Kit (JDK) for compiling a Java application. How can I install JDK on [insert your Linux distro]?

When developing a Java application or a Java-based component, you first need to set up Java development environment. For that, you install JDK on your Linux system. JDK contains a collection of Java programming tools, as well as a complete Java runtime environment.

There are two options to install JDK on Linux: Oracle JDK or OpenJDK. The latter is open-source implementation of Oracle's Java SE platform. Choose either one you prefer, as described in the following.

Install Oracle JDK on Linux

Go to Oracle website, and click on JDK Download link.

On the next page, you must accept Oracle license agreement. Then download JDK according to your Linux system:

After downloading a JDK file, install it on your Linux system as follows.

To install Oracle JDK on CentOS, Fedora or RHEL:

$ sudo rpm -ivh jdk-8u5-linux-<arch>.rpm

To install Oracle JDK on Debian, Ubuntu or Linux Mint:

$ sudo mkdir -p /usr/java
$ sudo tar xvfvz jdk-8u5-linux-<arch>.tar.gz -C /usr/java

After installation, define JAVA_HOME environment variable, and update PATH variable in your .bashrc file.

$ vi ~/.bashrc
JAVA_HOME=/usr/java/jdk1.8.0_05
PATH=$PATH:$JAVA_HOME/bin
$ source ~/.bashrc

Install OpenJDK on Linux

To install OpenJDK on Debian, Ubuntu or Linux Mint, first search for an available OpenJDK package (named openjdk-<version>-jdk) on your system:

$ apt-cache search openjdk

After checking the latest version of OpenJDK, install it with apt-get:

$ sudo apt-get install openjdk-7-jdk

To install OpenJDK on Fedora, CentOS or RHEL, first search for an available OpenJDK package (named java-<version>-openjdk-devel) on your system:

$ yum search openjdk

After checking the latest version of OpenJDK, install it with yum:

$ sudo yum install java-1.8.0-openjdk-devel

After installing OpenJDK, the final step is to define JAVA_HOME environment variable in your .bashrc file.

$ vi ~/.bashrc
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
$ source ~/.bashrc

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean