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

100

47

Since 11.10 Ubuntu does not provide the sun-java-jdk, how do I install it?

Rodja

Posted 2011-11-04T15:50:25.217

Reputation: 1 167

One other problem with openJDK (at least coupled with Nvidia cards) is when using Java2D, transparency is extremely slow, while with Sun it is blazing fast. – vextorspace – 2011-12-16T14:26:48.577

I have it in this post http://forum.xda-developers.com/showpost.php?p=19446284&postcount=62

– None – 2011-11-24T17:24:36.910

3Here's a quick tutorial for installing JDK7 on Ubuntu. – blackcompe – 2011-11-04T18:08:00.393

Answers

105

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)

JMax

Posted 2011-11-04T15:50:25.217

Reputation: 3 005

@Renaud I've approved the edit, in case somebody runs into the same issues. – slhck – 2011-11-22T10:45:05.427

Is there any up to date repo? – Paweł Prażak – 2012-04-22T18:12:41.020

@PawełPrażak: there is no point in downvoting when you didn't find what you expected... yet, I've edited the answer with a seeminlgy working solution for Ubundu 12.04. I cannot test it right here, please tell us if it works or edit the post with a wokring solution. – JMax – 2012-04-23T06:39:54.903

@JMax sorry, but I'm not sure what do you mean, the thing is that this repo contains 1.6.0_26 - it's outdated and have lots of unfixed security issues. But anyway I\ve found a almost perfect solution, see below :) – Paweł Prażak – 2012-04-25T17:46:55.463

9I get a bad error with these instructions for 12.04: sha256sum mismatch jdk-7u3-linux-x64.tar.gz Oracle JDK 7 is NOT installed. – Jay Taylor – 2012-05-28T05:46:28.163

@JayTaylor: are you sure your download worked properly? did you try it all over again? This kind of error is more likely a partial or incorrect download – JMax – 2012-05-28T19:01:54.010

2This failed for me as well. Same error. Nightmare. – Whit – 2012-05-29T19:13:30.117

@JayTaylor do not use ppa:eugenesan/java, it's broken. ppa:webupd8team/java works fine. – Ekevoo – 2012-06-13T01:39:48.043

on 11.10 sudo apt-get update returns this `W: GPG error: http://ppa.launchpad.net oneiric Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 2EA8F35793D8809A W: Failed to fetch http://ppa.launchpad.net/sun-java-community-team/sun-java6/ubuntu/dists/oneiric/main/source/Sources 404 Not Found

W: Failed to fetch http://ppa.launchpad.net/sun-java-community-team/sun-java6/ubuntu/dists/oneiric/main/binary-amd64/Packages 404 Not Found`

– SSH This – 2012-06-14T00:50:59.857

1

To install on 12.04, this was the only way I could do it: http://www.liberiangeek.net/2012/04/install-oracle-java-jdk-7-in-ubuntu-12-04-precise-pangolin/

– Steve HHH – 2012-06-15T05:02:14.887

This is terrible I wish I had read the comments, I wish I could downvote... please fix this. :( – z7sg Ѫ – 2012-06-20T21:42:46.497

1@z7sgѪ: please note that instead of complaining you can edit the answer, it will be peer reviewed and if relevand approved. This way, this (very old) answer will remain up-to-date. – JMax – 2012-06-21T05:16:36.213

2I needed to install oracle jdk 1.6 on lubuntu 12.04 and none of the provided PPA's worked. Didn't want to mess with binary installers so i just used add-apt-repository ppa:eugenesan/java and then replaced 'precise' with 'oneiric' in synaptic. So now I have 1.6.0_26 on precise - not the latest but enough for me. – ccpizza – 2012-07-07T17:52:52.730

The 12.04 way also works on 12.10 – Vlad Preda – 2013-04-13T21:20:17.113

Looks like eugenesan/java is some really-really nasty ppa. First of all it is broken. Even if I remove it from Software Center, it does not go away! I tried to purge it as well, still no luck. Had to reinstall the OS. – Bhushan – 2013-09-07T22:52:14.290

@JMax please remove this answer, as other people says its toxic! – Tommaso Barbugli – 2013-10-02T06:24:26.813

1@TommasoBarbugli: I've changed my answer to a community wiki. Feel free to edit and complete it if you think this is necessary – JMax – 2013-10-03T14:47:30.810

For those who corrupted your system, this link might be of your help http://askubuntu.com/a/126419/24203

– IsaacS – 2013-10-16T02:16:53.520

13

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

Paweł Prażak

Posted 2011-11-04T15:50:25.217

Reputation: 277

Cool solution, thanks: worked perfectly for me! – ngeek – 2012-04-24T13:07:57.377

1Nothing.[x] Installing Java build requirements failed [i] Showing the last 5 lines from the logfile (/home/me/oab-java6.sh.log)... Errors were encountered while processing: oracle-java7-installer E: Sub-process /usr/bin/dpkg returned an error code (1) 3135's retcode: 100 failed – Whit – 2012-05-29T19:16:58.443

You might want to file a bug report https://github.com/flexiondotorg/oab-java6/issues

– Paweł Prażak – 2012-05-30T18:20:41.810

1wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java6.sh says ERROR 404: Not Found. – SSH This – 2012-06-14T00:53:17.480

1

Works for me, check: https://github.com/flexiondotorg/oab-java6/blob/master/oab-java.sh

– Paweł Prażak – 2012-06-14T09:05:32.970

4

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

Peter Szanto

Posted 2011-11-04T15:50:25.217

Reputation: 151

Supplemental instructions for 12.04 available here: http://www.liberiangeek.net/2012/04/install-oracle-java-jdk-7-in-ubuntu-12-04-precise-pangolin/

– Steve HHH – 2012-06-15T05:02:50.283