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
“/usr/lib/jvm/jdk1.7.0/jre/bin/”
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
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_11
and
PATH=/usr/lib/jvm/jdk1.7.0_11/bin:$PATH in /etc/profile.d/java.sh
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 libnpjp2.so 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/libnpjp2.so

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/libnpjp2.so
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: ,

  • Ozie

    i have tried your instructions, but i get some problem when i execute command ‘java -version’ in last step..
    the terminal give output ‘cannot execute binary file’.
    can you give way for fix the problem???

  • http://shinephp.com Vladimir Garagulya

    I’m far away from my home desktop this week and can not test directly.
    Try to check execution ‘x’ permission for ‘java’ file. It seems that it have not such permission for some reason.

  • http://shinephp.com Vladimir Garagulya

    I’m far away from my home desktop this week and can not test directly.
    Try to check execution ‘x’ permission for ‘java’ file. It seems that it have not such permission for some reason.

  • Jacobus Reyneke

    Stunning, thanks, works like a charm ;-)

  • Pingback: Minecraft 1.7.3 + Bukkit + java 1.7 performance tuning. | Mac - Android - Scripting

  • Joneslee85

    There is now packaged openjdk-7 package for Debian / Ubuntu Oneiric in universe repository.

    $ sudo apt-get install openjdk-7-jre-headless

  • http://shinephp.com Vladimir Garagulya

    Thank you for this valuable information. This post becomes educational only now and can be used as manual for installing future Java releases before they appear in official Ubuntu repository.

  • Maddmann012001

    Can’t get it to work. Won’t let me change alternative selection. Mine is on number 1, java 6, manual. “java -version” puts out java 6

  • http://shinephp.com Vladimir Garagulya

    What
    sudo  update-alternatives –config java
    command shows to you. Please send its output here.

  • Ahsan

    Great post. I successfully configured java in my very first attempt.

  • http://shinephp.com Vladimir Garagulya

    Thank you for this acknowledgement.

  • http://shinephp.com Vladimir Garagulya

    Do you have any previous Java version installed? If haven’t, try to install openjdk 1.6 from Ubuntu repository first (use Sinaptic), then follow this post instructions.

  • Anonymous

    Thank you for the post. It worked the first time out!

  • Vin Tam

    Thanks for your instructions! It really works!
    To make the file executable, you may right click the icon for the file “” (i586 or x64) and check the box “Make file executable” OR type “chmod 777 jdk-7-linux-*.tar.gz” in Terminal
    If Terminal prints
    There is only one alternative in link group java: …
    Nothing to configure.
    after executing “sudo update-alternatives –config java”, don’t worry and execute “sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 1″

  • http://shinephp.com Vladimir Garagulya

    Thank you for such good addition.

  • Vin Tam

    You are welcome!
    At the bottom of my screenshot, the version of my java compiler is still 1.6.*
    To update it, it’s similar to what we do 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]
    Such a change in the file location on the right is needed as there’s NO “javac” in the directory “/usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/”

  • Alex

    Thanks, you saved my day :-)

  • rafael

    Nice, thank you for this guide.

    And how can I safely remove it ?

  • http://shinephp.com Vladimir Garagulya

    I think, it’s enough to make same steps in reverse order: select other Java version for update-alternatives and delete /usr/lib/jvm/jdk1.7.0 folder then.

  • Calreosbr_

    but I see not found updates for java what is my problem?? 

  • http://shinephp.com Vladimir Garagulya

    If you check updates via Synaptic Package Manager, then Ubuntu 10.04 has not Java 7 in its repository (correct me if I’m wrong guys). So you don’t see any updates for Java 7, while it took place from time to time for Java 6.

  • Raul Luna Rodriguez

    Sorry, but I have to say that these instructions doesn’t work. The problem is with the rest of the alternatives that remain linked with the old version. Commands like javac, jar, etc execute using the old JVM. To fix this, all the alternatives must be updated. I’ve tried to do it, but they are more than 70 links to repair. Despite I made a script to fix them, it doesn’t work (two or three errors) and I gave up.

  • http://shinephp.com Vladimir Garagulya

    Thanks for sharing. Vin Tam have commented about this issue already in concern to javac command. Yes, you are fully right – it is critical for Java developer to check all rest links and it is a lot of work. If you upload your script here with notes about what errors it has I appreciate this. May be someone will help to fix them and community will have full decision for problem of Java manual installation on Ubuntu 10.04.

    As for me I need Java to run NetBeans IDE for PHP development only. So changing link to java command only is enough for my purposes.

  • Ryan Northrup

    I’m getting the same error.  Yes, OpenJDK 1.6.0 is installed from Ubuntu’s repository.

    I’m running the x64 version of Lubuntu 11.04.

    Is there an alternative method to doing this other than the update-alternatives command?

    EDIT: Apologies, we might be getting different errors:

    “northrup@Pinkie-Pie:/usr/lib/jvm$ sudo update-alternatives –config java
    There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk/jre/bin/java
    Nothing to configure.”

  • leandrw

    The best tuto on the web!

  • Pingback: Instalar JDK 7.0 en Ubuntu 11.04 « El Blog de Héctor García

  • John Smith Paraggua

    for those who have no java installed on their computers, it will show an error on
    “sudo update-alternatives –config java”
    if this happens, continue to next step
    “sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 0″
    it should work
    check with
    java -version.

  • http://shinephp.com Vladimir Garagulya

    Try this command according to Vin Tam’s contribution above:
    if Terminal prints “There is only one alternative in link group java: …
    Nothing to configure.” after executing “sudo update-alternatives –config java”, don’t worry and execute “sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 1″

  • Sankri

    Thank you very much for your notes. It works

  • Jairusan

    Awesome, it just works! I did it with debian squeeze 64bit and the java version I was using is jdk 1.0.7 64bit as well.  Thank you so very much for making the life of newbies little bit better little by little.

  • http://shinephp.com Vladimir Garagulya

    You are welcome!
    That’s a pleasure to get so good comments. Thanks to you.

  • Pranav

    That was much helpful.Thanks

  • Woo

    <censored> Oracle change your politic please

  • Showtime

    Many thanks to u! Good job man!

  • Mel

    Your instructions worked like a charm.  How can I now uninstall java 6 now that java 7 is loaded?

    Thanks.

  • http://shinephp.com Vladimir Garagulya

    As you probably didn’t install Java 6 manually, use Synaptic Package Manager in System-Administration menu to uninstall it. In order to see installed java packages from Sun input ‘java6′ as keyword into Synaptic search box. Use ‘openjdk’ keyword to find alternative java packages.

  • RafaCL

    Gracias. Todo detalle por detalle. Se te agradece el aporte importante.

  • Priska

    while executing this command:

    sudo update-alternatives –config javaI have an issue : no alternatives for javaHow to solve it?Thank you

  • http://shinephp.com Vladimir Garagulya

    Try this command then:
    sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/java 0

  • Ariesjd

    when i type the last command “java -version” i get the following error:
    “bash: /usr/bin/java: no se puede ejecutar el fichero binario” what can i do
    please help me i need to work with netbeans 7!!

  • http://shinephp.com Vladimir Garagulya

    It seems you have some problem with configuration.
    Check output of
    update-alternatives –config java
    command again. See what java module is selected currently and try to execute it directly, not via alias ‘java -version’ but something like /usr/lib/jvm/jdk1.7.0/jre/bin/java -version
    If it isn’t executed check if you have some typo in the path, etc.

  • Paras

    hi valdamir, 
    I am having same problem as above, and when I execute the command suggested by you, 
    I am getting the following error

    update-alternatives: –install needs Usage: update-alternatives  …

    Please help,

    Regards,
    Paras.

  • http://shinephp.com Vladimir Garagulya

    Hi Paras,

    The answer is in the command output:
    update-alternatives: –install needs link name path priority
    Check command you executed for possible typos. Or send its copy here for checking.
    It should have 4 parameters after –install option. Every parameter should be separated from others by spaces.
    link: /usr/bin/java
    name: java
    path: /usr/lib/jvm/jdk1.7.0/jre/bin/java
    priority: 0

  • jGuru

    That’s fine and dandy for the java binary but what about the other binaries and plugins…
    Type javac -version and you will most likely get jdk_1.6.20…

  • http://shinephp.com Vladimir Garagulya

    You are right. There is the comment from Vin Tam about it already. I repeat it for your reference:
    At the bottom of my screenshot, the version of my java compiler is still 1.6.*
    To update it, it’s similar to what we do 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]
    Such
    a change in the file location on the right is needed as there’s NO
    “javac” in the directory “/usr/bin/java java /usr/lib/jvm/jdk1.7.0/jre/bin/”

    The same you should make for other Java binaries you use.

  • Pingback: To Do List After installing Ubuntu 11.10 aka Oneiric Ocelot |

  • Roberto

    Thank you very much! Very useful!

  • Benito

    Thank you very much!! It’s very useful. I install JDK 7 on Debian Wheezy

  • http://shinephp.com Vladimir Garagulya

    You are welcome! Thanks for the information.

  • Andrey Loskutov

    Hi,

    I’ve filed RFE “Provide debian package/installer for Oracle Java JDK/JRE”, please vote for it:

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7108196

    Regards,
    Andrey