go to  ForumEasy.com   
JavaPro  
 
 
   Home  |  MyForum  |  FAQ  |  Archive    You are not logged in. [Login] or [Register]  
Forum Home » Ubuntu » How To Install Java On Ubuntu 16.04 Box
Email To Friend  |   Set Alert To This Topic Rewarding Points Availabe: 0 (What's this) New Topic  |   Post Reply
Author Topic: How To Install Java On Ubuntu 16.04 Box
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/20/2017 12:06:47 AM    Edit  |   Quote  |   Report 
How To Install Java On Ubuntu 16.04 Box
Java and the JVM (Java's virtual machine) are widely used and required for many kinds of software. This thread is to instruct you to install and manage different versions of Java on Ubuntu 16.04 box.

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/20/2017 12:08:44 AM    Edit  |   Quote  |   Report 
Install the Default JDK

$ sudo apt-get update
$ sudo apt-get install default-jdk


Where does it locate?
$ which java
/usr/bin/java


Which version is installed?
$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/20/2017 12:11:43 AM    Edit  |   Quote  |   Report 
Install the Oracle JDK
First, add Oracle's PPA, then update your package repository
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update


Then specify the version you want to install

JDK 8
$ sudo apt-get install oracle-java8-installer


or JDK 9

$ sudo apt-get install oracle-java9-installer


http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/
jdk-8u144-linux-x64.tar.gz?AuthParam=1508369709_cd8d89c9ea21969593c7114b6684b14b
Connecting to download.oracle.com (download.oracle.com)|23.72.38.162|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-10-18 16:33:09 ERROR 404: Not Found.

download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 oracle-java8-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)


That's not right which means the auto process (apt-get install) is broken. We have to go the manual way.

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/20/2017 12:34:44 AM    Edit  |   Quote  |   Report 
Manually Install Oracle JDK
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

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/20/2017 12:44:41 AM    Edit  |   Quote  |   Report 
Manage Different Versions of Java

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
 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/20/2017 12:55:07 AM    Edit  |   Quote  |   Report 
Set the JAVA_HOME Environment Variable
Many java applications need to know where to load the JDK based on environment parameter JAVA_HOME

We can set it inside file /etc/environment:
$ sudo nano /etc/environment


Add at the end of file with this line:
JAVA_HOME="/usr/local/java/jdk1.8.0_152"


Save and exit the file, and reload it (or logout and login):
$ source /etc/environment


You can now verify it:
$ echo &JAVA_HOME
/usr/local/java/jdk1.8.0_152

 Profile | Reply Points Earned: 0

 
Powered by ForumEasy © 2003-2005, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.