Installing Oracle Java JDK on Ubuntu


Due to licensing restrictions, Ubuntu no longer comes with Oracle’s Java JDK.

The first trick to installing on a headless server is being able to wget the file. I recommend downloading manually and then placing in on a host you control, your Dropbox directory, etc.

You can install it by running:

sudo mkdir -p /opt/java/64
cd /opt/java/64
sudo wget
sudo tar -zxvf jdk-7u45-linux-x64.gz
sudo rm jdk-7u45-linux-x64.gz
sudo update-alternatives --install /usr/bin/java java /opt/java/64/jdk1.7.0_45/bin/java 2000 \
    --slave /usr/bin/javac javac /opt/java/64/jdk1.7.0_45/bin/javac \
    --slave /usr/bin/javadoc javadoc /opt/java/64/jdk1.7.0_45/bin/javadoc \
    --slave /usr/bin/javah javah /opt/java/64/jdk1.7.0_45/bin/javah \
    --slave /usr/bin/javap javap /opt/java/64/jdk1.7.0_45/bin/javap

To verify:

$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Be Sociable, Share!