Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to install Oracle's JRE and to update their lastest version through Update-Manager everytime they released. Is there a Ubuntu package that is provided by Canonical or Oracle?

Before release Java 7, I followed this way to install Java 6.

But it doesn't work for Java 7. There is no package sun-java7-xxx. How can you install Java 7?

share|improve this question
To install Oracle Java 6/7/8 JRE/JDK via package management, see: "How do I update Oracle Java 7 (JDK and JRE)". – BuZZ-dEE Apr 18 at 9:27
Officially recommended method: help.ubuntu.com/community/Java#Oracle_Java_7 – SalmanPK Apr 30 at 12:36

9 Answers

There is a similar question on how to install JDK 7

Install the JRE

Download the 32bit or 64bit Linux "compressed binary file" - it has a ".tar.gz" file extension and uncompress it

tar -xvf jre-7-linux-i586.tar.gz

JRE 7 package is extracted into ./jre1.7.0 directory. Now move the JRE 7 directory to /usr/lib

sudo mv ./jre1.7.0* /usr/lib/jvm/jre1.7.0

Afterwards run the following to get a list of currently installed java alternatives

sudo update-alternatives --config java

You will get output as:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode

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

Remember the last number and press enter to exit this utility i.e. in this example remember the number 2.

If only one alternative is shown then remember the number 0

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.7.0/bin/java 3

This will add your new JRE 7 installation into alternatives list i.e. use the remembered number + 1 i.e. 3 in the example above. Now configure java to use the Oracle Java JRE

sudo update-alternatives --config java

You will see output similar one below - choose the number of jre1.7.0 i.e. 3:

There are 3 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
3 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode

Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jre1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.

N.B. if there was no previous java installation then the new JRE will be the default and you will not see the above.

Check the version of you new JRE 7 installation:

java -version

Should produce

java version “1.7.0”
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode) 

Install the Firefox/Chrome plugin

In a terminal:

mkdir ~/.mozilla/plugins

Remove the IcedTea plugin, if it has been installed.

sudo apt-get remove icedtea6-plugin

Remove a former version of the Java plugin (may or may not be present)

rm ~/.mozilla/plugins/libnpjp2.so

Now you can install the plugin, by creating a symbolic link (you tell Firefox, where the plugin is located). For 32bit java use

ln -s /usr/lib/jvm/jre1.7.0/lib/i386/libnpjp2.so ~/.mozilla/plugins/

For 64bit java use

ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Confirm that the JRE has been successful by using the official oracle website.

share|improve this answer
5  
After running sudo update-alternatives --config java, I get the following output:There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk/jre/bin/java Nothing to configure. What am I doing wrong? – Shoan Mar 18 '12 at 4:56
6  
great answer, thanks! Wonder why Oracle can't spend the time to make packages for this.... – bbqchickenrobot Mar 26 '12 at 22:11
1  
@Shoan, in that case, go to step "if only one alternative is shown then remember the number 0" – henrique Mar 27 '12 at 1:57
3  
Thank you for this answer, Oracles instructions are rubbish for a linux noob, this made things alot easier! – David Barker May 9 '12 at 9:33
Thanks! Now I can finally use the Sun JVM! EDIT: crud, this breaks Minecraft on my 64-bit system. (Strange, considering that the specifically ask you to use Sun's JVM.) The launcher opens OK, but when I try to launch it, I get the Black Screen, even after deleting my ~/.minecraft/bin/ folder, and then updating. Running from the terminal, it gives me some gibberish about wrong ELF type, and that it's probably an architecture mismatch. (The official Java verifier on the Oracle site says everything's fine, though...) – JamesTheAwesomeDude Nov 11 '12 at 21:24
show 3 more comments

On AMD64 you need modify a little the command to create the symbolic link:

ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

only change the i386 to amd64.

share|improve this answer
Good shout! Wasn't working on my 12.04 64-bit until I read your answer. Thanks! – Scaine Jul 11 '12 at 18:43

The answer

First the answer, then the explanation. Open a terminal and copy and paste the following, line by line.

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

This will build the official sun-java6-* packages and make them available in the software-center. If you also want oracle-java7-* packages, run the script like this:

sudo ./oab-java.sh -7

Now you can install the packages with your preferred package manager.

The explanation

When Oracle changed the distribution license for Java, Linux distributions weren't allowed to update the official packages anymore. Github user rraptorr took the Debian script that was used to build the packages until then, and modified it to work with the updated downloads from Oracle. He now provides packging scripts for SUN Java6 and Oracle Java7.

Github user flexiondotorg wrote a wrapper for these scripts (at https://github.com/flexiondotorg/oab-java6) that automatically downloads the current version, creates the packages and adds them to a local repository.

Further notes

Packages created and installed using this method, will not receive updates automatically - only when you rerun the script. You can circumvent this by creating a cronjob that runs this script on a regular basis. The savest way to do this is using anacron by putting the script in /etc/cron.daily.

wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java.sh -O /root/oab-java.sh
chmod +x /root/oab-java.sh
ln -s /root/oab-java.sh /etc/cron.daily/oab-java

Now your official Java packages will always be up-to-date.

share|improve this answer
I've had so many issues with this script -_- – qodeninja Sep 25 '12 at 5:04
@qodeninja, like what? I've never had an issue with this script. Executing the 3 line above will definately work on every Ubuntu machine, if it is not broken. – mniess Sep 26 '12 at 16:28
I have a new linode instance of ubuntu 10.04 and I was trying to install jre 7 with this script. The script would hang for far too long because of missing dependencies. Then I had to stop the script and install the dependencies myself with apt-get. Even after I had everything installed the script still failed. – qodeninja Sep 26 '12 at 18:20
The script really doesn't do anything special. Sounds like something is wrong with your box. I have been (and am) using this from 8.04 to 12.04 and never had problems. I just tried this on my 10.04 server which is pretty much vanilla, and it works as well. As it should, because this script doesn't do more than use the old debian build-scripts that packagers used to provide sun-java* for debian (and ubuntu). – mniess Sep 27 '12 at 22:27

I propose one way to make easier the installation of Oracle's Java 7.

Since Ubuntu does not provides the Oracle's Java 7 packages, I'm providing a collection of Ubuntu packages on my own package repository.

The packages are fully integrated in the Ubuntu way to support Java. You will be able to select the Oracle's Java 7 alternative with the standard tools: update-alternative or update-java-alternative.

The main page of my contribution is: http://www.arakhne.org/jdk/index.html

To obtain the packages, you only need to add my package repository into your system configuration. The process is explained in http://www.arakhne.org/ubuntu.html

Stéphane.

share|improve this answer
8  
... just friendly advice - check oracle's redistribution license ... you dont want oracle's lawyers chasing you! – fossfreedom May 9 '12 at 11:44

To make it available for all users :

sudo ln -s /usr/lib/jvm/jre1.7.0/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins/

for x86_64 :

sudo ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins/
share|improve this answer
Many thanks! This is what was missing for my java to work on firefox. – ThiagoPonte Nov 6 '12 at 13:42

I think that the best method has been already posted but I had some problem with this : namely I remove java 'manuallyfromupdate-alternatives` and then I have tried to do this

update-alternatives --install "/usr/bin/java/" "java" "/usr/lib/jvm/jre1.7.0_05/bin/java" 1

but I kept on getting this error

update-alternatives: using /usr/lib/jvm/jre1.7.0_05/bin/java to provide /usr/bin/java/ (java) in auto mode. update-alternatives: error: unable to make /usr/bin/java/.dpkg-tmp a symlink to /etc/alternatives/java: No such file or directory

But fortunately I have encountered a great tutorial on this site : http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html and it worked just fine :)

share|improve this answer

For installing the 32-bit variant of Java on 64-bit Ubuntu:

Open up a terminal window ( Ctrl + Alt + T is the quickest method if you're not aware) and type in the following to install:

sudo add-apt-repository "deb http://download.tuxfamily.org/arakhne/ubuntu precise-arakhne universe"

wget http://download.tuxfamily.org//arakhne/public.key -O - | sudo apt-key add -
apt-get install ia32-oracle-java7-jre
share|improve this answer

For me it's a little bit different. For Ubuntu 12.04 LTS Precise (Desktop):

  1. Download jre-*.tar.gz

  2. tar -zxvf jre-*.tar.gz

  3. mkdir /usr/lib/jvm/

  4. mv jre* /usr/lib/jvm/

  5. ln -s /usr/lib/jvm/jre*/bin/java /usr/bin/

That's all.

To make sure it's correct:

java -version

If you want to add plug in for Firefox or Chrome:

  1. mkdir ~/.mozilla/plugins

  2. ln -s /usr/lib/jvm/jre*/lib/i386/libnpjp2.so ~/.mozilla/plugins/

Special Note: If you have a fresh 64 bit install, you may experience the following error when running java -version

-bash: ./java: No such file or directory

This is caused by a dependency on the libc6-i386 package which is not included by default in 64 bit Ubuntu Desktop 12.04 LTS. To install this package, run: sudo apt-get install libc6-i386

share|improve this answer
1  
The instructions you provide to add a plugin for Firefox or Chrome do not affect Chrome at all. Chrome does not use the contents of the .mozilla folder. – Eliah Kagan Jul 3 '12 at 0:46

AN UPDATED ANSWER:

I suggest using one of the installers from the webupd8team ppa in this way:

1) Enter these 2 commands in the Terminal to add this PPA and update your packages list:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

2) Enter one (or more) of these commands to install the proprietary Java(s) you require:

  • sudo apt-get install oracle-java6-installer
  • sudo apt-get install oracle-java7-installer
  • sudo apt-get install oracle-java8-installer

3) When the respective Java installer script is loaded and then it downloads and installs the proprietary Java packages, you can also enter the following command to check the result of the installation:

java -version

You should then get a terminal output (for java8) like this:

java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b54)
Java HotSpot(TM) Server VM (build 24.0-b21, mixed mode)

Further info: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

share|improve this answer

protected by Community Nov 20 '12 at 13:42

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.