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