In this article, We are going to perform How to Download and Install Oracle JAVA 12 on Ubuntu 18.04/16.04 LTS Manually or any other cloud platform like Amazon Ec2, Azure VM, Google Cloud Compute,etc. with preinstalled Ubuntu OS.
Introduction
Java is a set of software and specifications developed at Sun Microsystems. There are two tyes of Java Platforms are JDK (Java Development Kit) and JRE (Java Runtime Environment). Both are helpful for deploying applications on servers and debugging, JVM monitoring,developing.
Prerequisites
- Ubuntu Server 16.04/18.04 LTS
- SSH access with sudo privileges
To check Ubuntu version:
$ uname -a
OR
$ cat /etc/os-release
Output:
NAME="Ubuntu" VERSION="18.04.3 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.3 LTS" VERSION_ID="18.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=bionic UBUNTU_CODENAME=bionic
Follow the below steps to Install Oracle Java 12 on Ubuntu Manually using command line.
Step 1: Download Oracle Java 12
Generally Oracle will not allow to download directly without accepting their licences. We have to create one account in Oracle java website by your personal or official mail. After accepting licence download the application from browser to local machine.
This link takes you to the Oracle home website Oracel Java SRE.
Once you opened above link goto “Java SE Development Kit 12.0.2” section, click on download “jdk-12.0.2_linux-x64.bin.tar.gz” and “Accept License Agreement” and setup for ubuntu.
After downloading into local machine, using SCP/SFTP/FTP transfer the file from local machine to Ubuntu server.
Step 2: Copy downloaded Setup and Extract
Create a directory /opt/jdk
$ sudo mkdir -p /opt/jdk
Copy the tar file from the directory copied from local machine to server to /opt/jdk folder and execute below command:
$ sudo cp -rf /home/fosstechnix/jdk-12.0.2_linux-x64_bin.tar.gz /opt/jdk
Navigate to /opt/jdk directory
$ cd /opt/jdk/
Extract the Oracle Java 12 setup
$ sudo tar -zxf jdk-12.0.2_linux-x64_bin.tar.gz
Now unarchived the file and check the content by long-list:
# ls
Step 3: Install Oracle Java 12 on ubuntu with Alternatives
Use update-alternatives command to configure java on your system
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk-12.0.2/bin/java 2
After executing above command it shows below output:
Output:
update-alternatives: using /opt/jdk/jdk-12.0.2/bin/java to provide /usr/bin/java (java) in auto mode Now set default java 12
Note : Its not particularly o/p if you have installed open jdk before
Step 4: Verify Update Alternatives
Enter below command shows output:
$ sudo update-alternatives --display java
Output:
java - auto mode link best version is /opt/jdk/jdk-12.0.2/bin/java link currently points to /opt/jdk/jdk-12.0.2/bin/java link java is /usr/bin/java/opt/jdk/jdk-12.0.2/bin/java - priority 2
Set the default Oracle Java 12 using below command
$ sudo update-alternatives --config java
It prompts for selecting by 0,1,2..so choose accordingly, if you have already installed any oracle java.
Here I have not installed any other oracle java version, so I am getting output like below.
Output
sudo update-alternatives --config javaThere is only one alternative in link group java (providing /usr/bin/java): /opt/jdk/jdk-12.0.2/bin/javaNothing to configure.
Step 5: Setting the JAVA Environment Variables
To set JAVA environment variables, create a new file under /etc/profile.d directory.
$ sudo nano /etc/profile.d/javajdk.sh
Paste the below lines
export PATH=$PATH:/opt/jdk/jdk-12.0.2/bin export JAVA_HOME=/opt/jdk/jvm/jdk-12.0.2/ export J2SDKDIR=/opt/jdk/jvm/jdk-12.0.2/
To Load environment variables, Enter below command,
$ source /etc/profile.d/javajdk.sh
Step 6: Verify Java Version
To check the java version:
$ java -version
Output:
java version "12.0.2" 2019-07-16 Java(TM) SE Runtime Environment (build 12.0.2+10) Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing) you seeing output like above then we have successfully set up the Java 12 on Ubuntu.
Conclusion
In this article, We have have covered install oracle java 12 on Ubuntu, downloaded Oracle Java 12 from official site, installed using command line, configured JAVA_HOME and JRE_HOME, verified installed version.
Related Articles:
How to Download and Install Oracle JAVA 11 on Ubuntu 18.04/16.04 LTS
How to Download and Install Oracle Java 8 on CentOS 7
How to Download and Install Oracle JAVA 8 on Ubuntu 18.04/16.04 LTS