Downloading Oracle Java JDK
Using your web browser, go to the Oracle Java SE (Standard Edition) website and decide which version you want to install:
- JDK: Java Development Kit. Includes a complete JRE plus tools for developing, debugging, and monitoring Java applications.
- JRE: Java Runtime Environment. For deploying Java applications on servers. Includes tools for JVM monitoring and tools commonly required for server applications.
In this tutorial we will be installing the JDK Java SE Development Kit 8 – x64 bits.
Accept the license and copy the download link into your clipboard. Remember to choose the right tar.gz (64 or 32 bits).
Use wget to download the archive into your server:
wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/jdk-8u152-linux-x64.tar.gz
Oracle does not allow downloads without accepting their license, therefore we needed to modify the header of our request.
The /opt directory is reserved for all the software and add-on packages that are not part of the default installation. Create a directory for your JDK installation:
and extract java into the /opt/jdk directory:
tar -zxf jdk-8u152-linux-x64.tar.gz -C /opt/jdk
Verify that the file has been extracted into the /opt/jdk directory.
Using update-alternatives to choose default JVM
In our case, the java executable is located under /opt/jdk/jdk1.8.0_152/bin/java.
To set it as the default JVM in your machine run:
update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_152/bin/java 100
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_152/bin/javac 100
The output should look like this:
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)