How do I install the Sun/Oracle Java SDK on Ubuntu?

NOTE: Some of the contents of this answer might have become obsolete and there are some comments where people have reported problems. You're advised to read through the comments first.

--

Ubuntu 11.10 Oneric

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin

[Source]

Ubuntu 12.04 Precise

Clean up the historical open jdk:

sudo apt-get purge openjdk*

Add a new repo and install the sdk:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:eugenesan/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

If you want the JRE and the browser plugin:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

[Source]

Ubuntu 12.04 (Precise Pangolin) - another way

Thanks to the comments, please note that you can try this method too: http://www.liberiangeek.net/2012/04/install-oracle-java-jdk-7-in-ubuntu-12-04-precise-pangolin/

Make the sun java the default

You may want to also add the following

sudo update-alternatives --config java

You should get the following

Selection Path Priority Status

0 /usr/lib/jvm/java-7-oracle/bin/java 1 auto mode 1 /usr/lib/jvm/java-7-oracle/bin/java 1 manual mode * 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1 manual mode

Press enter to keep the current choice[*], or type selection number: 2

Select (2) and press enter

Now running:

java -version

Returns:

java version "1.7.0_04" Java(TM) SE Runtime Environment (build 1.7.0_04-b20) Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)


There is very good page on official Ubuntu wiki. There you can find all recommended methods. I've used this excellent automatic script.

Make sure git is installed:

sudo apt-get install git

Sun/Oracle Java 1.6.0

Build local debs:

wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh

Script will build packages from source and place them in local repo, then they can be installed e.g.:

sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-fonts sun-java6-source

You can see all available packages in /var/local/oab/deb

Remember to select the right version:

sudo update-alternatives --config java

To setup everything else (like browser plugin, keytool, etc.) you can use this (it will be a long list!):

sudo update-alternatives --all

The script is a wrapper for this Debian script, if you're curious ;)

Oracle Java 1.7.0_51

There is an Issue 123 currently in OAB and a pull request

Here is the patched vesion:

wget https://raw.github.com/ladios/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7

sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source 

Read more on AskUbuntu


You can install the official package from Oracle :

http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html

choose linux as your platform

Tags:

Java

Ubuntu

Sdk