Install Oracle Java JDK 7 in Ubuntu 12.04 (Precise Pangolin)

Last week we showed you how to install Oracle Java Runtime Environment (JRE) in Ubuntu 12.04. To read that post, click here.

In today’s post, I’m going to show you how to install Oracle Java (JDK) 7 in Ubuntu as well. There are some blogs that will show you how to install it via PPA, which is much easier, but then most PPA sources are not reliable. One day they’re up and the next they’re gone. This method is the surefire way to install Java JDK in Ubuntu.


  • Install Java JDK in Ubuntu 12.04 (Precise Pangolin)
  • Enjoy!

To get started, download Java JDK package from here.

When prompted with the screen below, choose to save the file.




After saving, extract the downloaded package by running the commands below. This assumes that the package was downloaded in your Downloads folder.

tar -xvf ~/Downloads/jdk-7u3-linux-i586.tar.gz




Next, create a folder for Java JDK files and folders by running the commands below.

sudo mkdir -p /usr/lib/jvm/jdk1.7.0 




Then move all the JDK files and folders to the new location by running the commands below.

sudo mv jdk1.7.0_03/* /usr/lib/jvm/jdk1.7.0/




Next, copy and paste each command as shown below one-at-a-time to enable Java JDK. Remember to press Enter after each line.

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


Then create a Mozilla plugins folder in your home directory.

mkdir ~/.mozilla/plugins/




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

ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/ ~/.mozilla/plugins/




That’s it! Enjoy!



  1. Gary Stafford - February 5, 2013 @ 11:03 PM

    Great posts on installing Java JDK and JRE on Ubuntu. Very accurate and quick. Worked perfect, first. Thank you.

  2. GryfonN - February 6, 2013 @ 2:07 AM

    Maybe you should also write how to set JAVA_HOME variable.

    1; # vim /etc/profile.d/
    2; contains:

    export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
    export PATH=$PATH:$JAVA_HOME/bin
    3; # source /etc/profile
    4; DONE !

  3. TRD - February 15, 2013 @ 3:11 PM

    Great instructions. In order to replace the default open JDK (which ships with ubuntu) with oracle/Sun JDK the following additional steps have to be performed

    sudo update-alternatives –config java
    sudo update-alternatives –config javac
    sudo update-alternatives –config javaws
    each of the above 3 commands will show you a list of all java versions been installed on your ubuntu system,please select the number which contains the path you just created in step 2

    • Vinni - September 18, 2013 @ 10:11 AM

      After updating using above 3 commands, perfectly updated open JDK with Oracle JDK.

      Thank you,

  4. Mike Nguyen - March 10, 2013 @ 3:49 PM

    I got this error after typing:
    sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.7.0/bin/java” 1

    The error reads:
    update-alternatives: error: alternative link is not absolute as it should be: usr/bin/java

    Any idea?


  5. pammu - May 30, 2013 @ 12:32 PM

    It’s one of the best tutorials I have ever come across. Thanks a ton to the author. It worked for me for the first time itself. Your effort is measureless. Thanks again.

  6. Jagdeep Singh - June 17, 2013 @ 1:06 PM

    sudo update-alternatives –install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/jdk1.7.0/bin/javaws” 1

    After implement this one error is occured

    update-alternatives: error: alternative path /usr/lib/jvm/jdk1.7.0/bin/javaws doesn’t exist

    Now How to solve this error

  7. Mariano - September 26, 2013 @ 11:09 AM

    Excelent. Thank you.

  8. Massih - October 25, 2013 @ 2:34 PM

    One of the best tutorial I have ever seen, Thank you so much !!!

  9. Gaurav - October 26, 2013 @ 2:01 AM

    Great article, very useful for me and others. i was just searching for backups in fedora 19, but it also helps in getting idea for backups in linux

  10. Fitz - February 5, 2014 @ 4:11 AM

    The last step errors:

    ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/ ~/.mozilla/plugins/
    ln: failed to create symbolic link `/home/fitz/.mozilla/plugins/': File exists

    Is this due to the symbolic link created from the previous tutorial for JRE?

    I do not know what to do now??

  11. assad - February 6, 2014 @ 3:09 AM

    i have this error
    update-alternatives: erreur: le chemin alternatif /usr/lib/jvm/jdk1.7.0/bin/java n’existe pas.

  12. Bap - February 24, 2015 @ 7:07 AM

    good information thank you

Leave a Reply

Your email address will not be published / Required fields are marked *