Install JDK 7 on Ubuntu

Install JDK 7 on Ubuntu

Install JDK 7 on Ubuntu

Task: Install JDK 7 on Ubuntu desktop.
Problem 1: Java version 7 is not available from Ubuntu repositories for your Ubuntu version (prior to 11.10 Oneiric). You don’t see it neither via "Ubuntu Software Center" nor via "Synaptic Package Manager".
What to do: Download JDK 7 binaries from the official Java site.
Problem 2: You are Debian/Ubuntu user and don’t see applicable .deb package.
What to do: Again, download JDK 7 binaries from the official Java site, install and configure it manually.
Step by step instructions to install and manual configure JDK 7 on the Ubuntu 10.04 LTS (the Lucid Lynx) desktop follow:
– For my X64 Ubuntu 10.04 LTS Desktop installation I downloaded Linux x64 – Compressed Binary file named jdk-7-linux-x64.tar.gz.
– Unpack it with command
gzip -d jdk-7-linux-x64.tar.gz
You will get jdk-7-linux-x64.tar file.
– Extract files from tar archive with command
tar -xvf jdk-7-linux-x64.tar
JDK 7 package is extracted into ./jdk1.7.0 directory.
– Move JDK 7 directory to place where it should be. Right, to the /usr/lib/jvm/jdk1.7.0 directory. Use this command for that
sudo mv ./jdk1.7.0/ /usr/lib/jvm/jdk1.7.0
– Execute this command
sudo update-alternatives --config java
to know under what number you will config you new Java installation. You will get output as:

$sudo update-alternatives –config java
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.
– Execute this command
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 3
to add your new JDK 7 installation into alternatives list. I put 3 there as 2 was last number for my configuration. You should use your own number from the previous step increased by 1.
– Execute this command
sudo update-alternatives --config java.
You will see output similar one below:

$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.

In case you have other answer from update-alternatives --config java command, e.g. ‘no alternatives for java’, try this command:

sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 0

This will select needed java version in case you had not any previous java version installed before.

The job is done. Task is completed and work is finished. Just check version of your new JDK 7 installation typing this command java -version. You should see something like this:

~$ java -version
java version “1.7.0”
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

Please be aware that we changed alias just for one java binary only – “java” itself. There are a lot of others in Java package, e.g. “javac” compiler, etc. If you try to check javac version with “javac -version” command the most probably you will get that it still has 1.6 version, e.g. on my box:

~$ javac -version
javac 1.6.0_26

To update it, make the same as you did for java runtime environment:
sudo update-alternatives –config javac // Check the java compilers you have
sudo update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0/bin/javac [-number]
Pay attention on the change of file location at the end of command. It is needed as there’s NO “javac” in the directory
we used for JRE configuration in previous command.
Apply this technique for other Java binaries you use.

Do not forget to change the PATH and JAVA_HOME to
PATH=/usr/lib/jvm/jdk1.7.0_11/bin:$PATH in /etc/profile.d/
according to your java version of course.

Thanks to Nikolavp’s blog for the hints about manual JDK 7 installation and configuration.

This post was written for Ubuntu 10.04 some time ago. These days with Ubuntu 12.04 and even 12.10 we have alternative, more convenient way to install original Java 7 package from Oracle.
Use this comprehensive manual about installation of Oracle JDK 7 via PPA repository. Recently, I installed JDK 7 via PPA on my fresh Ubuntu 12.04 using this manual without any problem. Thanks to Andrew for his brilliant support.

In order to configure Java Plugin from latest installed Java for your favorite Mozilla FireFox browser make this:
– Exit Firefox browser if it is already running.
– Uninstall any previous installations of Java Plugin, just remove all old symbolic links from the browser plugins directory.
– Create a symbolic link to the file in the browser plugins directory
Go to the plugins sub-directory under the Firefox installation directory
cd <Firefox installation directory>/plugins
– Create the symbolic link
ln -s <Java installation directory>/lib/i386/

For example, if Firefox is installed at this directory /usr/lib/firefox-10.0.2 and if Java is installed at this directory /usr/lib/jvm/jdk1.7.0 then type in the terminal window to go to the browser plug-in directory:
cd /usr/lib/firefox-10.0.2/plugins
Enter the following command to create a symbolic link to the Java Plug-in for the Mozilla browser.
sudo ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/
replace ‘i386’ with ‘amd64’ if you have 64 bit Ubuntu installation.

Start the Firefox browser. In Firefox, type about:plugins in the Location bar to confirm that the Java Plugin is loaded.

To test that Java plugin is installed and working properly on your FireFox browser, run this test applet.

Original source of information is Configure and Enable Java Plugin for FireFox.

You can make this decision even more universal. Place symbolic link for Java browser plugin to /usr/lib/mozilla/plugins/ folder. This way it will work not for the FireFox browser only, but for the Google Chrome browser too, as it uses the same /usr/lib/mozilla/plugins/ directory to get its plugins.

Tags: ,

  • Hi,

    I voted for it and left a comment to support this RFE. And you, guys? 
    What do you think about probability of successful development of native Debian/Ubuntu installer for Oracle Java JDK by Oracle?

  • Ovidiu-Florin Bogdan

    on Ubuntu 11.10, you already have it in the repository: openjdk-7-jdk openjdk-7-jre

  • Asdrúbal Iván Suárez Rivera

    Wow!! Thank you! This helped me 🙂

  • Guest

    Ubuntu has the special mechanism of update-java-alternatives  Based on the files /usr/lib/jvm/.XXXX.jinfo

    Therefore I found 
    that generates this file and sets all update-alternatives –install /usr/……

    you have to set
    as described in this document and afterwards java, javac, …. sets to jdk1.7.0_01

  • Oh, it’s interesting! Thanks for sharing this useful information. I will definitely investigate this feature for future use.

  • rjw

    I did all that and get the following error:
    ubuntu@ubuntu:/usr/lib/jvm/jdk1.7.0_01/jre/bin$ sudo update-alternatives –config javaThere 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/jdk1.7.0_01/jre/bin/java      3         manual modePress enter to keep the current choice[*], or type selection number: 2update-alternatives: using /usr/lib/jvm/jdk1.7.0_01/jre/bin/java to provide /usr/bin/java (java) in manual mode.ubuntu@ubuntu:/usr/lib/jvm/jdk1.7.0_01/jre/bin$ java -version-bash: /usr/bin/java: No such file or directory

    I don’t understand why this comes up… as /usr/bin/java exists when I look it up! Can anybody help me?

  • /usr/bin/java is a symbolic link to /etc/alternatives/java
    Look in /etc/alternatives/java file using 
    $view /etc/alternatives/java
    command and check 1st line. I have 
    … symbolic link to `/usr/lib/jvm/jdk1.7.0/jre/bin/java’ 
    there. Error message that file or directory doesn’t exist is concerned to this file or directory, not /usr/bin/java, so re-check if all is OK with path, you  see in this line.

  • Arunkumar Jeyapal

    Thank you very much

  • Kubuntu

    Thank you!

  • Manoharan S

    Thanks a lot!!

  • lostanew

    I have already installed java-6-openjdk, java-7-openjdk-amd64, and now jdk1.7.0. I also noted that I have two files in my download folder: jdk-7-linux-x64.tar.gz and jdk-7u2-linux-x64.tar.gz. (I tried a few things before getting to this website). So maybe I installed jdk-7 twice now. lol

  • That’s not a problem, more work – more experience and knowledge :). Just be sure that you use the latest Java release.

  • Edf

    doesn’t work

  • Rafael

    works fine but i would like to have a more direct way to change all the aliases than to change them one by one…
    there is a way of defining a file /usr/lib/.jdk1.7.0.jinfo (copied for example to the one generated by java-6-openjdk) but when i try “sudo update-java-alternatives -s jdk1.7.0” it doesn’t want to work !
    Any idea ?

  • cocoandco

    Hi, I’ve done all the steps and finally when I run : java -version I have fichier binaire impossible à lancer, any idea ?

  • Check if you have this file /etc/alternatives/java 
    Try to execute java with full path
    If you get same error message, check if your java file has ‘eXecution’ permission.

  • Amritasah89

    really gr88… thanks alot… 🙂 🙂

  • Douglas

    Thanks. It worked fine but when I right click to open a .jar (namely Minecraft) I don’t have an option to use 7. The only option is still ‘Open JDK Java 6 Runtime’. I’m guessing there is something more I need to do.

  • Amosleaf

    谢谢博主。 按照这个步骤在我的ubuntu上面 很好使。
    Thanks a lot, it work well in my box by your step.

  • m93a

    Thaaaaaanks! Yeah! It works! I don’t have to launch Windows now! 😀

  • You are welcome! 🙂

  • Leandro Martínez

    Thanks for the post. But how about the browser plugin? My browser does not seem to recognize that java is installed at all on the machihe after these steps.

  • Leandro Martínez

     Actually installing the sun-java6-plugin does the job, but asking if I wan to run an outated plugin every time.

  • Thanks for the question. I added section about configuring FireFox Java Plugin for the latest installed Java version. Please look at the end of the post above.

  • Yang

    Thank you!!

  • That really helped. Thanks a lot 🙂

  • Tbsoft2001

    This is great. I need v. 7 to run a specific program and this did it.

    Something to look at:

    $sudo mv ./jdk1.7.0/ /usr/lib/jvm/jdk1.7.0

    should be

    $sudo mv jdk1.7.0/ /usr/lib/jvm/jdk1.7.0

    as the folder’s name is ‘jdk1.7.0’ (with no quotes).

  • Metajeffrey

    Well I’ll be horn-swaggled: it worked! I am running Xubuntu and was having trouble installing a JDK because the distributions available on Oracle’s site were only .rpm (which Ubuntu doesn’t use) and tar.gz. The self-extracting “.bin” of earlier distributions was no longer available. Your instructions made it simple. Thanks!

  • Almost Anon

    Thanks, best walk-through available, worked on Ubuntu 11.04.

  • Shadin

    Does this work on Ubuntu 11.10 ?

  • Thingy

    Thanks, saved me a lot of hassle

  • I didn’t tried, but generally, it should, as the way of JDK installation on Ubuntu box was not changed.

  • Saurabh Snt

    Cool article, helped a lot! thanks 🙂


    thanx a lot….this s really helpful….works fine with ubuntu 12.04….thnx again

  • Ike

    Awesome, the perfect guide.

  • Diego de Souza Silva

    Thank you! Worked really fine for me

  • Thanks, that works! on ubuntu 12.04 64 bit

  • Thanks a lot, guys, for your word of appreciation.

  • update-alternatives: error: unknown argument `–install’
    pls help

  • You should use –install parameter, not –install, that is double hyphen before parameter name. Try “update-alternatives –help” to see available options and syntax.

  • eugene

    The manual is great but what it does not say is
    that you have to change the PATH and JAVA_HOME to
    JAVA_HOME=/usr/lib/jvm/jdk1.7.0_11 ,
    PATH=/usr/lib/jvm/jdk1.7.0_11/bin:$PATH in /etc/profile.d/ which
    was quite confusing. The rest is fine. Burn in hell Oracle.

  • Thank you for this valuable addition.

  • eugene

    Вы извините за то, что ответ немного эмоциональный. Половину своего выходного дня  потратил на решение проблемы.

  • Нет проблем. Статью я написал после решения своей собственной узкой проблемы – установить JDK 7 для NetBeans for PHP. Непосредственно с Java я не работаю, поэтому для меня пройти описанный путь оказалось достаточно.
    Я включил ваше дополнение в статью, может ещё кому пригодится.
    Кстати существует уже custom PPA для автоматической установки Oracle JDK 7 через PPA-репозиторий.
    Я включил ссылку на нужный пост
    в конец статьи.

  • Radek Kozik

    It’s sudo update-alternatives –install with two dashes

  • Grover Mamani