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

If I downloaded the latest JDK from Oracle. Do I just download the .tar file, and extract it at /usr/lib/jvm/?

share|improve this question
3  
I would also like to point out that using OpenJDK is more than a viable alternative: it is also the reference implementation now. – nickguletskii Nov 12 '12 at 16:40
openJdk is not supported by banks applets or by other software. example: Aptana Studio – Elzo Valugi Mar 14 at 19:34
1  
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:28

10 Answers

There is a similar question on how to install JRE 7.

Install the JDK

  • Download he 32bit or 64bit Linux "compressed binary file" - it has a ".tar.gz" file extension i.e. "[java-version]-i586.tar.gz" for 32bit and "[java-version]-x64.tar.gz" for 64bit
  • Uncompress it

    tar -xvf jdk-7u2-linux-i586.tar.gz (32bit)

    tar -xvf jdk-7u2-linux-x64.tar.gz (64bit)

JDK 7 package is extracted into ./jdk.1.7.0_02 directory. N.B. check carefully this folder name since Oracle seem to change this occasionally with each update.

  • Now move the JDK 7 directory to /usr/lib
sudo mkdir -p /usr/lib/jvm
sudo mv ./jdk.1.7.0_02 /usr/lib/jvm/jdk1.7.0
  • Now run
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
  • Correct the file ownership and the permissions of the executables:
sudo chmod a+x /usr/bin/java 
sudo chmod a+x /usr/bin/javac 
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.7.0

N.B. remember - Java JDK has many more executables that you can similarly install as above. java, javac, javaws are probably the most frequently required.

This answer lists the other executables available.

  • Run
sudo update-alternatives --config java

You will see output similar one below - choose the number of jdk1.7.0 - for example 3 in this list:

$sudo update-alternatives --config java
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/jdk1.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/jdk1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.

Check the version of you new JDK 7 installation:

java -version

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) 

Repeat the above for:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Enable mozilla firefox plugin:

32 bit:
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

64 bit:
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

N.B. you can link the plugin (libnpjp2.so) to /usr/lib/firefox/plugins/ for a system wide installation

Depending on your configuration, you might need to update the apparmor profile for firefox (or other browsers) in /etc/apparmor.d/abstractions/ubuntu-browsers.d/java

# Replace the two lines:
#  /usr/lib/jvm/java-*-sun-1.*/jre/bin/java{,_vm} cx -> browser_java,
#  /usr/lib/jvm/java-*-sun-1.*/jre/lib/*/libnp*.so cx -> browser_java,
# with those (or adapt to your new jdk folder name)
/usr/lib/jvm/jdk*/jre/bin/java{,_vm} cx -> browser_java,
/usr/lib/jvm/jdk*/jre/lib/*/libnp*.so cx -> browser_java,

Then restart apparmor:

sudo /etc/init.d/apparmor restart

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

For Java 6:

If you're on a fresh installation of Ubuntu with no previous Java installations, this script automates the process outlined above if you don't want to type all that into a console. Remember, you still need to download Java from Oracle's website -- Oracle's links are not wget friendly.

Before using this make sure that this script is in the same directory as the .tar.gz file extension that you downloaded and there are no files that start with jdk-7 in the same folder -- if there are, please move them out of the folder temporarily. Remember to make the script executable, either by doing chmod +x <script's directory> or right clicking the document, pressing properties, going to the Permissions tab, and checking "Allow executing file as a program."

#!/bin/sh

tar -xvf jdk-7*
sudo mkdir /usr/lib/jvm
sudo mv ./jdk1.7* /usr/lib/jvm/jdk1.7.0
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws

If you want to install the plugin for Firefox then add this to the end of the script

mkdir ~/.mozilla/plugins
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
sudo /etc/init.d/apparmor restart

Confirm if Java has been properly installed.

java -version

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

share|improve this answer
Is necessary to do all the same process to update it? – Lucio yesterday

The link has instructions for installing Oracle JDK, the Java 7 browser plugin and how to revert the changes.

So here is a tested (under Ubuntu 11.04 and 11.10) and working solution for installing Oracle JDK 7 and all its files so "javac" and everything else works: How To Install Oracle Java 7 (JDK) In Ubuntu

Here are the commands (just for convenience):

  1. Download the latest Oracle JDK 7 from here.
  2. Extract the downloaded Oracle Java JDK archive in your home folder - a new folder called "jdk1.7.0_03" (for Java JDK7 update 3) should be created. Rename it to "java-7-oracle" and move it to /usr/lib/jvm using the following commands:
cd
sudo mkdir -p /usr/lib/jvm/      #just in case
sudo mv java-7-oracle/ /usr/lib/jvm/

3. Install Update Java package created by Bruce Ingalls (packages available for Ubuntu 11.10, 11.04, 10.10 and 10.04):

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install update-java

4. Now run the following command in a terminal to install Oracle Java JDK:

sudo update-java

Select the Java Version that you want to install and set as the default

After a few minutes, Oracle Java JDK should be successfully installed on your Ubuntu machine. You can check out the version by running these commands in a terminal:

java -version
javac -version
share|improve this answer
I think this script would work for Gnome (tools) but requires a lot of additional installs as for Kubuntu machine (eg. missing gksudo on Kubuntu). – Marcin Gil Jan 12 '12 at 9:36
good and relatively painless solution on Precise, just installed jdk1.7.0_03 on it – prusswan Feb 24 '12 at 6:55
I just used this method to put jdk1.7.0_03 on Precise beta 2, as well. It worked, although an error was reported (in Zenity, evidently); the error doesn't appear to have affected the result. – Kelley Apr 20 '12 at 16:28

From http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html :

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-jdk7-installer
share|improve this answer
5  
I am wondering why most people are tempted to use the first answer, which is quite complex and requires a lot of manual work, like downloading the installer on your machine and moving it to the server. Your answer is simple and effective!!! TX – Sorin Sbarnea Jul 25 '12 at 15:02
1  
@SorinSbarnea Some people don't like to use third party repositories because they aren't always updated or online for that matter. – umop aplsdn Aug 27 '12 at 21:30
On Ubuntu server, I had to use "sudo apt-get install python-software-properties" to get the add-apt-repository command. – Mark Butler Mar 13 at 7:11
@SorinSbarnea because the repository is generally well out of date – dstarh Apr 22 at 15:31

This is how I installed it in Oneiric just now. It will be a rather lengthy answer, but it worked for me.

Download latest Java SDK 1.7.0 from Oracle. Then extract it to /usr/lib/jvm:

$ cd /usr/lib/jvm/
$ sudo tar -xvzf ~/jdk-7-linux-x64.tar.gz
$ sudo mv jdk1.7.0 java-7-oracle
$ sudo ln -s java-7-oracle java-1.7.0-oracle

After that I created .java-1.7.0-oracle.jinfo file in /usr/lib/jvm with the following contents:

alias=java-7-oracle
priority=100
section=non-free

jre ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-7-oracle/jre/bin/java
jre java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-7-oracle/jre/bin/jcontrol
jre keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool
jre pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200
jre policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool
jre rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200
jre orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd
jre servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool
jre tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv
jre jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer
jdk apt /usr/lib/jvm/java-7-oracle/bin/apt
jdk extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck
jdk idlj /usr/lib/jvm/java-7-oracle/bin/idlj
jdk jar /usr/lib/jvm/java-7-oracle/bin/jar
jdk jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner
jdk java-rmi.cgi /usr/lib/jvm/java-7-oracle/bin/java-rmi.cgi
jdk javac /usr/lib/jvm/java-7-oracle/bin/javac
jdk javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc
jdk javah /usr/lib/jvm/java-7-oracle/bin/javah
jdk javap /usr/lib/jvm/java-7-oracle/bin/javap
jdk jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole
jdk jdb /usr/lib/jvm/java-7-oracle/bin/jdb
jdk jhat /usr/lib/jvm/java-7-oracle/bin/jhat
jdk jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo
jdk jmap /usr/lib/jvm/java-7-oracle/bin/jmap
jdk jps /usr/lib/jvm/java-7-oracle/bin/jps
jdk jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd
jdk jstack /usr/lib/jvm/java-7-oracle/bin/jstack
jdk jstat /usr/lib/jvm/java-7-oracle/bin/jstat
jdk jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd
jdk native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii
jdk rmic /usr/lib/jvm/java-7-oracle/bin/rmic
jdk schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen
jdk serialver /usr/lib/jvm/java-7-oracle/bin/serialver
jdk wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen
jdk wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport
jdk xjc /usr/lib/jvm/java-7-oracle/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so

Then you need to tell update-alternatives about all the new stuff:

$ sudo -sH
Password:
# update-alternatives --quiet --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
# update-alternatives --quiet --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
# update-alternatives --quiet --install /usr/bin/appletviewer appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer 100 --slave /usr/share/man/man1/appletviewer.1 appletviewer.1 /usr/lib/jvm/java-7-oracle/man/man1/appletviewer.1
# update-alternatives --quiet --install /usr/bin/apt apt /usr/lib/jvm/java-7-oracle/bin/apt 100 --slave /usr/share/man/man1/apt.1 apt.1 /usr/lib/jvm/java-7-oracle/man/man1/apt.1
# update-alternatives --quiet --install /usr/bin/extcheck extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck 100 --slave /usr/share/man/man1/extcheck.1 extcheck.1 /usr/lib/jvm/java-7-oracle/man/man1/extcheck.1
# update-alternatives --quiet --install /usr/bin/idlj idlj /usr/lib/jvm/java-7-oracle/bin/idlj 100 --slave /usr/share/man/man1/idlj.1 idlj.1 /usr/lib/jvm/java-7-oracle/man/man1/idlj.1
# update-alternatives --quiet --install /usr/bin/jar jar /usr/lib/jvm/java-7-oracle/bin/jar 100 --slave /usr/share/man/man1/jar.1 jar.1 /usr/lib/jvm/java-7-oracle/man/man1/jar.1
# update-alternatives --quiet --install /usr/bin/jarsigner jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner 100 --slave /usr/share/man/man1/jarsigner.1 jarsigner.1 /usr/lib/jvm/java-7-oracle/man/man1/jarsigner.1
# update-alternatives --quiet --install /usr/bin/javac javac /usr/lib/jvm/java-7-oracle/bin/javac 100 --slave /usr/share/man/man1/javac.1 javac.1 /usr/lib/jvm/java-7-oracle/man/man1/javac.1
# update-alternatives --quiet --install /usr/bin/javadoc javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc 100 --slave /usr/share/man/man1/javadoc.1 javadoc.1 /usr/lib/jvm/java-7-oracle/man/man1/javadoc.1
# update-alternatives --quiet --install /usr/bin/javah javah /usr/lib/jvm/java-7-oracle/bin/javah 100 --slave /usr/share/man/man1/javah.1 javah.1 /usr/lib/jvm/java-7-oracle/man/man1/javah.1
# update-alternatives --quiet --install /usr/bin/javap javap /usr/lib/jvm/java-7-oracle/bin/javap 100 --slave /usr/share/man/man1/javap.1 javap.1 /usr/lib/jvm/java-7-oracle/man/man1/javap.1
# update-alternatives --quiet --install /usr/bin/jconsole jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole 100 --slave /usr/share/man/man1/jconsole.1 jconsole.1 /usr/lib/jvm/java-7-oracle/man/man1/jconsole.1
# update-alternatives --quiet --install /usr/bin/jdb jdb /usr/lib/jvm/java-7-oracle/bin/jdb 100 --slave /usr/share/man/man1/jdb.1 jdb.1 /usr/lib/jvm/java-7-oracle/man/man1/jdb.1
# update-alternatives --quiet --install /usr/bin/jhat jhat /usr/lib/jvm/java-7-oracle/bin/jhat 100 --slave /usr/share/man/man1/jhat.1 jhat.1 /usr/lib/jvm/java-7-oracle/man/man1/jhat.1
# update-alternatives --quiet --install /usr/bin/jinfo jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo 100 --slave /usr/share/man/man1/jinfo.1 jinfo.1 /usr/lib/jvm/java-7-oracle/man/man1/jinfo.1
# update-alternatives --quiet --install /usr/bin/jmap jmap /usr/lib/jvm/java-7-oracle/bin/jmap 100 --slave /usr/share/man/man1/jmap.1 jmap.1 /usr/lib/jvm/java-7-oracle/man/man1/jmap.1
# update-alternatives --quiet --install /usr/bin/jps jps /usr/lib/jvm/java-7-oracle/bin/jps 100 --slave /usr/share/man/man1/jps.1 jps.1 /usr/lib/jvm/java-7-oracle/man/man1/jps.1
# update-alternatives --quiet --install /usr/bin/jrunscript jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript 100 --slave /usr/share/man/man1/jrunscript.1 jrunscript.1 /usr/lib/jvm/java-7-oracle/man/man1/jrunscript.1
# update-alternatives --quiet --install /usr/bin/jsadebugd jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd 100 --slave /usr/share/man/man1/jsadebugd.1 jsadebugd.1 /usr/lib/jvm/java-7-oracle/man/man1/jsadebugd.1
# update-alternatives --quiet --install /usr/bin/jstack jstack /usr/lib/jvm/java-7-oracle/bin/jstack 100 --slave /usr/share/man/man1/jstack.1 jstack.1 /usr/lib/jvm/java-7-oracle/man/man1/jstack.1
# update-alternatives --quiet --install /usr/bin/jstat jstat /usr/lib/jvm/java-7-oracle/bin/jstat 100 --slave /usr/share/man/man1/jstat.1 jstat.1 /usr/lib/jvm/java-7-oracle/man/man1/jstat.1
# update-alternatives --quiet --install /usr/bin/jstatd jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd 100 --slave /usr/share/man/man1/jstatd.1 jstatd.1 /usr/lib/jvm/java-7-oracle/man/man1/jstatd.1
# update-alternatives --quiet --install /usr/bin/native2ascii native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii 100 --slave /usr/share/man/man1/native2ascii.1 native2ascii.1 /usr/lib/jvm/java-7-oracle/man/man1/native2ascii.1
# update-alternatives --quiet --install /usr/bin/rmic rmic /usr/lib/jvm/java-7-oracle/bin/rmic 100 --slave /usr/share/man/man1/rmic.1 rmic.1 /usr/lib/jvm/java-7-oracle/man/man1/rmic.1
# update-alternatives --quiet --install /usr/bin/schemagen schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen 100 --slave /usr/share/man/man1/schemagen.1 schemagen.1 /usr/lib/jvm/java-7-oracle/man/man1/schemagen.1
# update-alternatives --quiet --install /usr/bin/serialver serialver /usr/lib/jvm/java-7-oracle/bin/serialver 100 --slave /usr/share/man/man1/serialver.1 serialver.1 /usr/lib/jvm/java-7-oracle/man/man1/serialver.1
# update-alternatives --quiet --install /usr/bin/wsgen wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen 100 --slave /usr/share/man/man1/wsgen.1 wsgen.1 /usr/lib/jvm/java-7-oracle/man/man1/wsgen.1
# update-alternatives --quiet --install /usr/bin/wsimport wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport 100 --slave /usr/share/man/man1/wsimport.1 wsimport.1 /usr/lib/jvm/java-7-oracle/man/man1/wsimport.1
# update-alternatives --quiet --install /usr/bin/xjc xjc /usr/lib/jvm/java-7-oracle/bin/xjc 100 --slave /usr/share/man/man1/xjc.1 xjc.1 /usr/lib/jvm/java-7-oracle/man/man1/xjc.1
# update-alternatives --quiet --install /usr/bin/java-rmi.cgi java-rmi.cgi /usr/lib/jvm/java-7-oracle/bin/java-rmi.cgi 100
# update-alternatives --quiet --install /usr/bin/ControlPanel ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel 100
# update-alternatives --quiet --install /usr/bin/java java /usr/lib/jvm/java-7-oracle/jre/bin/java 100
# update-alternatives --quiet --install /usr/bin/java_vm java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm 100
# update-alternatives --quiet --install /usr/bin/javaws javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws 100
# update-alternatives --quiet --install /usr/bin/jcontrol jcontrol /usr/lib/jvm/java-7-oracle/jre/bin/jcontrol 100
# update-alternatives --quiet --install /usr/bin/keytool keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool 100
# update-alternatives --quiet --install /usr/bin/pack200 pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200 100
# update-alternatives --quiet --install /usr/bin/policytool policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool 100
# update-alternatives --quiet --install /usr/bin/rmid rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid 100
# update-alternatives --quiet --install /usr/bin/rmiregistry rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry 100
# update-alternatives --quiet --install /usr/bin/unpack200 unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200 100
# update-alternatives --quiet --install /usr/bin/orbd orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd 100
# update-alternatives --quiet --install /usr/bin/servertool servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool 100
# update-alternatives --quiet --install /usr/bin/tnameserv tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv 100
# update-alternatives --quiet --install /usr/bin/jexec jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec 100

Now you can use update-alternatives to select newly installed Java SDK.

# update-alternatives --config java              # Select java-1.7.0-oracle
# update-java-alternatives --set java-1.7.0-oracle
# exit
$

This worked for me, if there is a more elegant way (without using third-party PPAs) I'd be glad to hear about it. I still need to test Firefox if I can run Java in it.

share|improve this answer
Works great, except the final command issues an error (though everything else works, even in Firefox/Chrome). This seems to be from the default OpenJDK6 install with Oneiric."update-alternatives: error: no alternatives for -javaplugin.so." In the hidden .java.1.6.0.jinfo file there seems to be an alternative pointing to -javaplugin.so. Are we supposed to make a 3rd alternative point to libnpjp2.so with it perhaps? – Nicholi Oct 25 '11 at 23:13
I decided to put the steps mentioned by BigWhale above in a simple shell script. The only manual step is to download the 64bit tar.gz from Oracle's site. Have a look at the instructions here. – julius May 29 '12 at 20:46

I wrote a blog post with a very detailed explanation on how to install Java 7 on Natty, both OpenJDK's and Sun's:

http://brunoreis.com/tech/intalling-java-ubuntu-natty/

OpenJDK is installed from the PPA provided by Damien Lecan, and Sun's is installed manually. As far as know, until now that is the only guide that is correct both in the steps and the explanation.

If you find any problems, post a comment there and I will try to fix it.

Good luck.

share|improve this answer
14  
please try not to link out to external stuff as an answer - give the most relevant parts in your answer. The reason is that external links may disappear in the future - and therefore others will not be able to refer to the answer in the future. Thanks. – fossfreedom Aug 17 '11 at 19:27

Get the JDK from Oracle/Sun, download the Java JDK at:

http://www.oracle.com/technetwork/java/javase/overview/index.html

Pls download or move the downloaded file to your homeDirectory ~ for ease.

Note :

  • Dont worry about what JDK to download for JEE.

  • Pls skip copying the Prompt " user@host:~$ ".

  • Hit enter after each command.

Run in a terminal..

user@host:~$ sudo mkdir -p /usr/lib/jvm/
user@host:~$ sudo mv jdk-7u4-linux-i586.tar.gz /usr/lib/jvm/
user@host:~$ cd /usr/lib/jvm/
user@host:~$ sudo tar zxvf jdk-7u4-linux-i586.tar.gz

Now enable Java (by running individually) :

user@host:~$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_04/bin/java" 1
user@host:~$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_04/bin/javac" 1
user@host:~$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_04/bin/javaws" 1

Close all browsers.

Create a Mozilla plugins folder in your home directory :

user@host:~$ mkdir ~/.mozilla/plugins/

Create a symbolic link to your Mozilla plugins folder. For 64-bit systems, replace ‘i386’ with ‘amd64’:

user@host:~$ ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

Testing:

user@host:~$ java -version

Output:

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)

Testing:

user@host:~$ javac -version

Output:

javac 1.7.0_04 

Verify JRE at http://java.com/en/download/installed.jsp

share|improve this answer

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
3  
... just friendly advice - check oracle's redistribution license ... you dont want oracle's lawyers chasing you! – fossfreedom May 9 '12 at 11:46
1  
Indeed, you might find that you need to make a package with scripts to retrieve Java from the Oracle site and present the user with the license agreement, rather than including the software in the package itself. (That's what's currently done with flashplugin-installer and msttcorefonts.) – Eliah Kagan May 27 '12 at 3:44

The easiest way is just downloading java 7 with Netbeans here - http://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-432126.html

share|improve this answer

Here's a bash script that could help in setting up the java alternatives:

#!/bin/bash

BIN_HOME="/usr/bin"
JVM_BIN_HOME="/usr/lib/jvm/jdk1.7.0_21/bin"

UPDATE_CMD="update-alternatives"
UPDATE_OPT="--install"
UPDATE_DEFAULT_PRIORITY=10

echo "Installing alternatives for Oracle JDK."
#echo "JAVA_BIN_HOME=$JAVA_BIN_HOME"
#echo "BIN_HOM=$BIN_HOME"
echo "All cmds in \"$JVM_BIN_HOME\" will be installed in \"$BIN_HOME\" with \"$UPDATE_CMD\""
echo

# 
# Calls update-alternatives.
# Param 1 is the java cmd name and optionally param 2 is the priority
# See 'man update-alternatives' for more information.
# 
function update_alt() {
    if [ -z "$2" -o "${2}xxx" = "xxx" ]; then
    echo "using default priority: $UPDATE_DEFAULT_PRIORITY"
    PRIORITY=$UPDATE_DEFAULT_PRIORITY
    else
    PRIORITY=$2
    fi

    EXEC="$UPDATE_CMD $UPDATE_OPT $BIN_HOME/$1 $1 $JVM_BIN_HOME/$1 $PRIORITY"
    echo $EXEC
    $EXEC
    return 0
}

for bin in $JVM_BIN_HOME/*
do
    if [ -x $bin ]; then
    cmd=$(basename $bin)

    if [ -x $BIN_HOME/$cmd ]; then
        echo "notice: alternative already installed, \"$cmd\""
        continue # Skip installation of alternative.
    fi

    echo "install alternative: $cmd"
    update_alt $cmd
    if [ ! -x $BIN_HOME/$cmd ]; then
        echo "error: failed to install alternative, \"$cmd\""
        exit 1
    fi
    fi
done

exit 0
share|improve this answer

Straightforward Solution

Rather than downloading the .tar.gz package I recommend you download the .rpm package. Then run:

sudo apt-get install alien dpkg-dev debhelper build-essential
sudo alien --scripts jdk-7u-linux-.rpm 

where I believe the current <build> is 21 and the <version> depends on your system architecture.

The first will install alien, a application for converting .rpm to .deb. The second command then runs alien on jdk package. This should run for a minute or two and produce a file labelled:

jdk-7u<build>-linux-<version>.deb

This package may then be installed by running:

sudo dpkg -i jdk-7u<build>-linux-<version>.deb

This is how I successfully installed it on my machine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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