How to install Java development kit (JDK) on Linux

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.

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:

  • For Non-RPM based Linux (e.g., Debian, Ubuntu, Mint): jdk-8u5-linux-i586.tar.gz (32-bit) or jdk-8u5-linux-x64.tar.gz (64-bit)
  • For RPM-based Linux (e.g., CentOS, Fedora, RHEL): jdk-8u5-linux-i586.rpm (32-bit) or jdk-8u5-linux-x64.rpm (64-bit)

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

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *