Java Language Installing Java (Standard Edition) Installing a Java JDK on Linux


Using the Package Manager

JDK and/or JRE releases for OpenJDK or Oracle can be installed using the package manager on most mainstream Linux distribution. (The choices that are available to you will depend on the distro.)

As a general rule, the procedure is to open terminal window and run the commands shown below. (It is assumed that you have sufficient access to run commands as the "root" user ... which is what the sudo command does. If you do not, then please talk to your system's administrators.)

Using the package manager is recommended because it (generally) makes it easier to keep your Java installation up to date.

apt-get, Debian based Linux distributions (Ubuntu, etc)

The following instructions will install Oracle Java 8:

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

Note: To automatically set up the Java 8 environment variables, you can install the following package:

$ sudo apt-get install oracle-java8-set-default

Creating a .deb file

If you prefer to create the .deb file yourself from the .tar.gz file downloaded from Oracle, do the following (assuming you've downloaded the .tar.gz to ./<jdk>.tar.gz):

$ sudo apt-get install java-package # might not be available in default repos
$ make-jpkg ./<jdk>.tar.gz          # should not be run as root
$ sudo dpkg -i *j2sdk*.deb

Note: This expects the input to be provided as a ".tar.gz" file.

slackpkg, Slackware based Linux distributions

sudo slapt-get install default-jdk

yum, RedHat, CentOS, etc

sudo yum install java-1.8.0-openjdk-devel.x86_64

dnf, Fedora

On recent Fedora releases, yum has been superseded by dnf.

sudo dnf install java-1.8.0-openjdk-devel.x86_64

In recent Fedora releases, there are no packages for installing Java 7 and earlier.

pacman, Arch based Linux distributions

sudo pacman -S jdk8-openjdk

Using sudo is not required if you're running as the root user.

Gentoo Linux

The Gentoo Java guide is maintained by the Gentoo Java team and keeps an updated wiki page including the correct portage packages and USE flags needed.

Installing Oracle JDKs on Redhat, CentOS, Fedora

Installing JDK from an Oracle JDK or JRE tar.gz file.

  1. Download the appropriate Oracle archive ("tar.gz") file for the desired release from the Oracle Java downloads site.

  2. Change directory to the place where you want to put the installation;

  3. Decompress the archive file; e.g.

    tar xzvf jdk-8u67-linux-x64.tar.gz

Installing from an Oracle Java RPM file.

  1. Retrieve the required RPM file for the desired release from the Oracle Java downloads site.

  2. Install using the rpm command. For example:

    $ sudo rpm -ivh jdk-8u67-linux-x644.rpm