Bookmark and Share

This is a note on my experience of installing Java on Ubuntu Linux 14.04.

The default Java packages on Ubuntu Linux openjdk-7-jdk is from OpenJDK. It should be more or less consistent with Java Language and Virtual Machine Specifications. However, on macOS computers, I use Oracle's JDKs for developing Java programs, and some softwares I use such as Android Studio warns that using OpenJDK can be problematic and recommends using Oracle's JDK instead. Therefore, I install Oracle's Java as a standard component on my Linux computers as well. Oracle calls it "Java Platform (JDK) Platform". JDK is Java Development Kit which is the software package one needs to do Java software development. It's currently at version "Java SE 7" and is updated to "JDK SE 8" in March 2014.

Installing Oracle JDK 7 using ppa

Install dependency:

sudo apt-get install python-software-properties

Install Oracle JDK using Webup8.org's PPA:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
# or if you want JDK 8:
# sudo apt-get install oracle-java8-installer

At command line verify java is pointing to Oracle JDK 7,

$ which java
/usr/bin/java
$ ls -la /usr/bin/java
lrwxrwxrwx 1 root 22 Jan 24 07:16 /usr/bin/java -> /etc/alternatives/java*
$ ls -la /etc/alternatives/java
lrwxrwxrwx 1 root 39 Jul  8 12:04 /etc/alternatives/java -> /usr/lib/jvm/java-7-oracle/jre/bin/java*

Installing Oracle JDK 8

$ sudo apt-get install oracle-java8-installer

Choosing default Java

Choose Java 7 as the default for java and javac:

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1073      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1072      manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1073      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-oracle/jre/bin/java to provide /usr/bin/java (java) in manual mode
$ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-oracle/bin/javac          1073      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/bin/javac   1071      manual mode
  2            /usr/lib/jvm/java-7-oracle/bin/javac          1072      manual mode
  3            /usr/lib/jvm/java-8-oracle/bin/javac          1073      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-oracle/bin/javac to provide /usr/bin/javac (javac) in manual mode
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

Setting the JAVA_HOME environment variable

On Ubuntu Linux, system environment variable can be set in /etc/environment by adding the line

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

Alternatively, set it in $HOME/.bashrc or $HOME/.bash_profile

References

blog comments powered by Disqus