Child pages
  • Oracle JDK

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

First, add the PPA:

Code Block
language
languagebash
themeEmacsbash
add-apt-repository ppa:webupd8team/java

Then update the software information:

Code Block
languagebash
themeEmacs
languagebash
apt-get update

Then install Java (replace 8 with another Java version you might want instead, like 6 or 7):

Code Block
languagebash
themeEmacs
languagebash
apt-get install oracle-java8-installer

The installer takes a while since it needs to download the latest Java installer from the Oracle site.

Anchor
SettingJavaEnvironmentVariables
SettingJavaEnvironmentVariables
Setting Java

...

Environment Variables

To automatically set up the Java 8 environment variables, you can install the following package:

Code Block
languagebash
themeEmacslanguagebash
sudo apt-get install oracle-java8-set-default

Below /etc/profile.d there are two files jdk.csh sh and jdk.sh csh who contain the environment variables definitions, here .

Here is the content of jdk.sh:

Code Block
themeEmacs
languagebashtext
export J2SDKDIR=/usr/lib/jvm/default-java-8-oracle
export J2REDIR=/usr/lib/jvm/default-java-8-oracle/jre
export PATH=$PATH:/usr/lib/jvm/default-java-8-oracle/bin:/usr/lib/jvm/default-java-8-oracle/db/bin:/usr/lib/jvm/default-java-8-oracle/jre/bin
export JAVA_HOME=/usr/lib/jvm/default-java-8-oracle
export DERBY_HOME=/usr/lib/jvm/default-java/db

Here is the content of jdk.csh:

Code Block
languagetext
setenv J2SDKDIR /usr/lib/jvm/default-java-8-oracle
setenv J2REDIR /usr/lib/jvm/default-java/jre
setenv PATH ${PATH}:/usr/lib/jvm/default-java/bin:/usr/lib/jvm/default-java/db/bin:/usr/lib/jvm/default-java/jre/bin
setenv JAVA_HOME /usr/lib/jvm/default-java
setenv DERBY_HOME /usr/lib/jvm/default-java/db

Verification

Make sure something silly didn't happen and your alternatives were set to Oracle Java:

Code Block
languagebash
themeEmacs
languagebash
java -version

Expected output (with Oracle Java 8):

Code Block
languagebash
themeEmacs
languagebash
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) Server VM (build 25.40-b25, mixed mode)

Wrong output (with OpenJRE)

Code Block
languagebash
themeEmacs
languagebash
OpenJDK Runtime Environment (IcedTea6 1.13.6) (6b34-1.13.6-1ubuntu0.12.04.1)
OpenJDK Server VM (build 23.25-b01, mixed mode)

Then

Code Block
languagebash
themeEmacs
languagebash
javac -version

Expected output (with Oracle Java 8):

Code Block
language
languagebash
themeEmacsbash
javac 1.8.0_40

(Without Oracle Java, OpenJDK is rarely installed)

If the wrong Java is chosen, run:

Code Block
languagebash
themeEmacslanguagebash
update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javaws

and choose Oracle's needed version.

Then run

Code Block
languagebash
themeEmacslanguagebash
update-initramfs -u

Troubleshooting

...

The installer fetches the latest Java binary via wget. Most of the time, the download fails because either the firewall blocks it or because the cacher doesn't allow it. Since Java updates are not very frequent, we can turn off the firewall while installing, but the cacher can at least be configured for a permanent bypass. Create /etc/apt/apt.conf.d/03java-bypass with the following contents:

Code Block
languagebash
themeEmacslanguagebash
title/etc/apt/apt.conf.d/03java-bypass
Acquire::http::Proxy {
    download.oracle.com DIRECT;
};

...