Installing a Java JDK on Linux
suggest changeUsing the Package Manager
JDK and JRE releases for OpenJDK or Oracle can be installed with the package manager on most mainstream Linux distributions. Which packages exist depends on the distribution.
As a general rule, open a 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 WebUpd8 PPA was discontinued in April 2019, and oracle-java8-installer is no longer published. On Debian and Ubuntu, install OpenJDK 8 with sudo apt-get install openjdk-8-jdk. The old PPA commands were:
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
Note: That same discontinued PPA also published a package that set the Java 8 environment variables:
$ 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. The generated .deb name depends on the java-package version; older versions used a j2sdk name.
Slackware
Slackware does not ship a Debian-style default-jdk package, and slapt-get is not slackpkg. Install the JDK package from your Slackware release or from SlackBuilds.
yum****, RedHat, CentOS, etc
sudo yum install java-1.8.0-openjdk-devel.x86_64
The .x86_64 suffix selects the 64-bit x86 package. Other architectures use a different suffix. The dnf example below has the same suffix.
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.
- Download the appropriate Oracle archive (“tar.gz”) file for the desired release from the Oracle Java downloads site.
- Change directory to the place where you want to put the installation;
- Decompress the archive file; e.g.
tar xzvf jdk-8u67-linux-x64.tar.gz
Installing from an Oracle Java RPM file.
- Retrieve the required RPM file for the desired release from the Oracle Java downloads site.
- Install using the
rpmcommand. For example:
$ sudo rpm -ivh jdk-8u67-linux-x64.rpm