Install Oracle Java Ubuntu
This ‘Install Oracle Java Ubuntu’ article informs about the installation process of Java 8 on Ubuntu in order to be used with big data frameworks such as Apache Hadoop or Apache Spark. It provides a step-wise installation guide.
Step 1 – Check Java Existence
We can verify the existence of Java in a system using the Java version command as shown below. If Java is installed it returns the version number but if it is not installed you may get an error message or a hint that Java is provided in several packages in the operating system. The output below provides an example from the Ubuntu Linux system.
$ java -version
Output:
The program 'java' can be found in the following packages: * default-jre * gcj-5-jre-headless * openjdk-8-jre-headless * gcj-4.8-jre-headless * gcj-4.9-jre-headless * openjdk-9-jre-headless Try: sudo apt install
Step 2 – Add Repository
We use the Ubuntu packet manager to install Java and need to add a repository as shown below. The Webupd8 Team is maintaining a PPA repository with installer scripts for the latest Java 8 and 9 distributions. It automatically downloads the Java archive from the Oracle website and sets up the installation as well.
$ sudo add-apt-repository ppa:webupd8team/java
Output:
Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA. More info (and Ubuntu installation instructions): - for Oracle Java 7: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html - for Oracle Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html Debian installation instructions: - Oracle Java 7: http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html - Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html Oracle Java 9 (for both Ubuntu and Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html For JDK9, the PPA uses standard builds from: https://jdk9.java.net/download/ (and not the Jigsaw builds!). Important!!! For now, you should continue to use Java 8 because Oracle Java 9 is available as an early access release! You should only use Oracle Java 9 if you explicitly need it, because it may contain bugs and it might not include the latest security patches! Also, some Java options were removed in JDK9, so you may encounter issues with various Java apps. More information and installation instructions (Ubuntu / Linux Mint / Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java Press [ENTER] to continue or ctrl-c to cancel adding it gpg: keyring `/tmp/tmpklob_7mz/secring.gpg' created gpg: keyring `/tmp/tmpklob_7mz/pubring.gpg' created gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com gpg: /tmp/tmpklob_7mz/trustdb.gpg: trustdb created gpg: key EEA14886: public key "Launchpad VLC" imported gpg: no ultimately trusted keys found gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) OK
Step 3 – Update and Install
Afterwards we update and install the installer script. This is done via the following commands to update the system package index and install Java installer scripts for Java. The example below is in Ubuntu but works similar in other Linux distributions.
$ sudo apt update; sudo apt install oracle-java8-installer
Output:
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Get:2 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease [17.6 kB] Get:3 http://advania-is-1a.clouds.archive.ubuntu.com/ubuntu xenial InRelease [247 kB] Get:4 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main amd64 Packages [2,864 B] Get:5 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main i386 Packages [2,864 B] Get:6 http://security.ubuntu.com/ubuntu xenial-security/main Sources [66.2 kB] ... Fetched 35.8 MB in 10s (3,384 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 124 packages can be upgraded. Run 'apt list --upgradable' to see them. Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: binutils gsfonts gsfonts-x11 java-common libfontenc1 libxfont1 oracle-java8-set-default x11-common xfonts-encodings xfonts-utils Suggested packages: binutils-doc binfmt-support visualvm ttf-baekmuk | ttf-unfonts | ttf-unfonts-core ttf-kochi-gothic | ttf-sazanami-gothic ttf-kochi-mincho | ttf-sazanami-mincho ttf-arphic-uming firefox | firefox-2 | iceweasel | mozilla-firefox | iceape-browser | mozilla-browser | epiphany-gecko | epiphany-webkit | epiphany-browser | galeon | midbrowser | moblin-web-browser | xulrunner | xulrunner-1.9 | konqueror | chromium-browser | midori | google-chrome The following NEW packages will be installed: binutils gsfonts gsfonts-x11 java-common libfontenc1 libxfont1 oracle-java8-installer oracle-java8-set-default x11-common xfonts-encodings xfonts-utils 0 upgraded, 11 newly installed, 0 to remove and 124 not upgraded. Need to get 6,518 kB of archives. After this operation, 20.5 MB of additional disk space will be used. Do you want to continue? [Y/n] ... Oracle JRE 8 browser plugin installed Oracle JDK 8 installed #####Important######## To set Oracle JDK8 as default, install the "oracle-java8-set-default" package. E.g.: sudo apt install oracle-java8-set-default On Ubuntu systems, oracle-java8-set-default is most probably installed automatically with this package. ###################### ...
Step 4 – Set Environment
As shown above the Oracle JRE 8 and the Oracle JDK 8 have been installed. As the output suggests we use the PPA again that also contains a package to automatically set Java environment variables. The command is as follows:
$ sudo apt install oracle-java8-set-default
Output:
Reading package lists... Done Building dependency tree Reading state information... Done oracle-java8-set-default is already the newest version (8u121-1~webupd8~2). oracle-java8-set-default set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 124 not upgraded.
Step 5 – Check Java Version
After the environment variables have been set we want to verify which Java version is available. We can use again the following command:
$ java -version
Output:
java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Install Oracle Java Ubuntu Details
There is an interesting video available for the installation: