Subject: Manage Different Versions of Java
Author: Linux
In response to: Manually Install Oracle JDK
Posted on: 10/20/2017 12:44:41 AM
Now the Ubuntu box has at least two versions of Java: the default openJDK & Oracle JDK. Here is how to manage what is to be used.
$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
2 /usr/local/java/jdk1.8.0_152/bin/java 100 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/local/java/jdk1.8.0_152/bin/java to provide /usr/bin/java (java) in manual mode
Here we chose Oracle JDK1.8 and linked it to
/usr/bin/java
>
> On 10/20/2017 12:34:44 AM
Linux wrote:
Step 1) Download the Oracle JDK package
There are two packages available for Linux: .rpm and .gz. Here, .gz is taken as example.
Download a JDK from http://download.java.net/. Look for ".gz" under "Linux" and download to local Windows machine.
Step 2). Make the folder available
$ sudo mkdir /usr/local/java
$ cd /usr/local/
$ sudo chmod 777 java
Step 3). Upload the downloaded JDK by WinSCP
Copy jdk-8u152-linux-x64.tar.gz onto /usr/local/java/
Step 4). Unzip the package
$ tar xzf jdk-8u152-linux-x64.tar.gz
The JDK content is under folder jdk1.8.0_152
Step 5). Install JDK Linkage
Format:
$ update-alternatives --install <link> <name> <path> <priority>
$ sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_152/bin/java 100
$ sudo update-alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.8.0_152/bin/jar 100
$ sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_152/bin/javac 100
References: