Ubuntu Linux: Install Latest Oracle Java 7

I am a network admin who recently made the switch from MS-Windows to Ubuntu Linux. I need to use Java and Firefox web browser plugin to run java applet. I am unable to access many devices such as Firewall appliance, LBS/VPX, and network equipments due to Ubuntu’s incompatible openjdk and icedtea plugin. I also searched software center but unable to find Oracle Java 7. How do I install Oracle Java 7 and get rid of this incompatibility problems on Ubuntu Linux amd64 v12.04 LTS or v13.04+?

Tutorial details
Difficulty level Intermediate
Root privileges Yes
Requirements apt-get/tar/ln
Est. reading time N/A
Debian / Ubuntu and much other Linux distros are switching to OpenJDK (Open Java Development Kit). It is a free and open source implementation of the Java Platform, Standard Edition (Java SE). OpenJDK is the official Java SE 7 reference implementation and following packages are installed on Ubuntu Linux:

  1. openjdk-7-jdk – OpenJDK Development Kit (JDK)
  2. openjdk-7-jre – OpenJDK Java runtime, using Hotspot JIT
  3. icedtea-plugin – web browser plugin to execute Java applets (dependency package)

Find out installed JDK

To list all currently installed java implementation on the system, enter:
$ dpkg --list | grep jdk
Sample outputs:

Fig.01: Listing all installed jdk's on Ubuntu Linux

Fig.01: Listing all installed jdk’s on Ubuntu Linux

You can also use the following command to list all installed packages providing information to set a bunch of java alternatives.
$ update-java-alternatives -l
Sample outputs:

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64

(Fig.02: A list of all installed JDK’s on the system

Finding out the default java version

Type the following command:
$ java -version
Sample outputs:

java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

(Fig.03: I am using OpenJDK 1.6 [openjdk and jre version 6])

Installing Oracle Java 7 On Ubuntu version 12.04 or 13.04+

The good news is you can install Oracle Java 7 easily and make it as the default source implementation of the Java platform. First, grab Oracle Java 7 directly from Oracle Java download page:

Fig.04: Download Oracle Java 7

Fig.04: Download Oracle Java 7

Make sure you download 32 bit (Linux x86 ~ jdk-7u21-linux-i586.tar.gz) or 64 bit (Linux x64 ~ jdk-7u21-linux-x64.tar.gz) JDK version in .tar.gz format:
Fig.05: Accept Oracle license and download either 64 or 32 bit version in tar.gz format

Fig.05: Accept Oracle license and download either 64 or 32 bit version in tar.gz format

Note: By default all files are downloaded in ~/Download/ ($HOME/Download/) directory.

Install jdk-7u21-linux-x64.tar.gz

Open a terminal and type the following command to list your files:
$ ls ~/Downloads/*.tar.gz
Sample outputs:


Untar the tar ball and install at /usr/lib/jvm/ directory:

sudo mkdir -p /usr/lib/jvm/
sudo tar xvf ~/Downloads/jdk-7u21-linux-x64.tar.gz -C /usr/lib/jvm

Sample outputs:


Oracle Java 7 has been installed in /usr/lib/jvm/jdk1.7.0_21/ directory. Type the following ln command to create a softlink:

cd /usr/lib/jvm
sudo ln -s jdk1.7.0_21 java-1.7.0-sun-amd64

Setting the default Java to use

Type the following command
$ sudo update-alternatives --config java
Sample outputs:

Fig.06: Setting the default Java to Oracle 7 Java

Fig.06: Setting the default Java to Oracle 7 Java

Update your ~/bashrc

Edit the file ~/bashrc, enter:

vi ~/bashrc

Set or update the JAVA_HOME and PATH shell variables as follows:

export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_21"
export PATH="$PATH:$JAVA_HOME/bin"

Save and close the file.

Verify new java settings

Type the following command:

java -version

Sample outputs:

java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

How do I configure Mozilla Firefox Java 7 plugin?

First, close running Firefox. Open a terminal and cd into /usr/lib/firefox-addons/plugins directory, enter:

cd /usr/lib/firefox-addons/plugins

Type the following command to create a softlink to libnpjp2.so, enter:

ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so .


ln -s /usr/lib/jvm/jdk1.7.0_21/jre/lib/amd64/libnpjp2.so .

How do I test whether Java is working on my Firefox?

Start the Firefox and visit this url to verify that Oracle 7 java Applet / plugin is working for Firefox:

Fig.07: Testing whether Java is working on my Firefox browser

Fig.07: Testing whether Java is working on my Firefox browser

So there you have it-the ultimate and official Oracle Java 7 JDK/JRE running on Ubuntu Linux and Firefox web-browser plugin.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 30 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
30 comments… add one
  • Danny May 17, 2013 @ 15:39

    I followed this guide to the letter (Kubuntu 13.04) but get this in response to:

    $ sudo update-alternatives –config java

    “There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
    Nothing to configure.”

    • 🐧 nixCraft May 17, 2013 @ 17:08

      It means java is working on your system and no other JDK installed.


  • genevieve May 23, 2013 @ 1:09

    Thanks for this, it works perfectly for me. Can you tell me where to find instructions for getting it to work in Chrome as well (not Chromium)?

  • Brian Jun 19, 2013 @ 15:48

    I see the same as Danny (17/May).

    I followed the steps to install the Oracle JDK up to and including the command:

    sudo ln -s jdk1.7.0_21 java-1.7.0-sun-amd64

    but after doing that I get no options when I run the command:

    sudo update-alternatives –config java

    What may be causing that?

    • Brian Jun 19, 2013 @ 16:35

      Replying to my own post, I think there’s a step missing in the instructions.

      I *think* that before running this command:

      sudo update-alternatives –config java

      You need to first run this command:

      sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/java-1.7.0-sun-amd64/bin/java” 1

      That seems to fix the problem.

      • Danny Jun 20, 2013 @ 7:39

        Following up on my original post (:-) I concur with what you discovered and all is good now. Thanks!

      • Nate Aug 3, 2013 @ 23:01

        When I run:
        sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/java-1.7.0-sun-amd64/bin/java” 1

        I get an error that I don’t understand:
        update-alternatives: error: alternative link is not absolute as it should be: “/usr/bin/java”

        Any ideas?

        • A Aug 13, 2013 @ 11:23

          Do not copy paste. Quotation marks and double dash in Brian’s post should be substituted to normal ones. It worked for me.

        • Ryan Hendry Jan 9, 2014 @ 21:01

          This worked for me:

          sudo update-alternatives --install '/usr/bin/java' 'java' '/usr/lib/jvm/java-1.7.0-sun-amd64/bin/java' 1
  • amin Jun 27, 2013 @ 12:54

    thank you for your instruction; i followed your instruction. after all you create softlink for it, and you wrote :
    sudo ln -s jdk1.7.0_21 java-1.7.0-sun-amd64
    but mine was :
    sudo ln -s jdk1.7.0_25 java-1.7.0-openjdk-amd64

    now when i run “java -version” i see this output:
    java version “1.7.0_05”
    Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
    Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

    but i downloaded 7u25 and install with your instruction.
    can you help me please ?

  • cplee Jun 28, 2013 @ 7:00

    Look at the reply post by Brian to Danny. Need to run the update-alternative with the –install option first. If not, ubuntu doesn’t know about the new jdk you just installed.


  • Dhiraj Singh Jul 2, 2013 @ 12:40

    When i enter the following command :
    sudo tar xvf ~/Downloads/jdk-7u21-linux-x64.tar.gz -C /usr/lib/jvm
    output :
    dhiraj@dhiraj-OptiPlex-320:~$ sudo tar xvf ~/Downloads/jdk-7u21-linux-x64.tar.gz -C /usr/lib/jvm
    tar: /home/dhiraj/Downloads/jdk-7u21-linux-x64.tar.gz: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now

    • kyle Dec 7, 2014 @ 1:12

      I think what will fix this is adding a slash at the end of your command. without the slash, you might be looking for a file named jvm instead of the directory that was created in a previous step.

      • kyle Dec 7, 2014 @ 1:13

        sorry I misread the error, you just need to make sure that the file you’re trying to untar is actually in the directory you’re saying it is. Also make sure the name of the file is spelled properly.

  • sachin Dua Jul 19, 2013 @ 5:09

    sachin@sachin-Lenovo-G550:~$ java -version
    java version “1.7.0_21″
    OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-1ubuntu1)
    OpenJDK Server VM (build 23.7-b01, mixed mode)
    when I apply this command this showe that java is installed in my system,but when I am going to compile any java program it gives the following error
    sachin@sachin-Lenovo-G550:~/programs$ javac abc.java
    The program ‘javac’ can be found in the following packages:
    * default-jdk
    * ecj
    * gcj-4.6-jdk
    * gcj-4.7-jdk
    * openjdk-7-jdk
    * openjdk-6-jdk
    Try: sudo apt-get install
    please tell me how to get rid of it & run my java program

  • BearFather Jul 19, 2013 @ 22:18

    Thank you Thank you Thank you. With Brian’s fix and this wonderful tutorial I’m finally got 1.7 installed.

  • nictrix Jul 22, 2013 @ 20:18

    I believe this is a typo in the article. vi ~/bashrc (it should show the dot, like below)

    vi ~/.bashrc

    And I think you’ll want to do a source ~/.bashrc after to verify the java installation properly.

  • Subhadip Jul 25, 2013 @ 18:28

    I have Oracle Java installed on Ubuntu 12.04 32 bit. Java is working fine on Firefox and Google Chrome but not on Chromium. Can anybody please help?

  • Tauseef Sep 6, 2013 @ 15:39

    i urgently need to install jdk..m stuck up with java -version command it shows tht u gta install using sudo apt-get…i didnt hav any alternatives so when i tried the command sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/java-1.7.0-sun-amd64/bin/java” 1…it tells command not found.pls help
    i hav ubuntu 12 LTE working on vmware.

  • Prasad Sep 11, 2013 @ 13:18

    You saved my ass.

    Gr8 post. I invested around 2 hours to get it done but nothing worked out.

    Then I came to this post and everthing is working fine now.
    Thanks a ton !!!

  • Stephen Sep 17, 2013 @ 19:53

    Thanks also from me, to quote BearFather “with Brian’s fix and this wonderful tutorial I’m finally got 1.7 installed.”

  • chad Sep 24, 2013 @ 18:19

    nice for a noob like me., help me a lot.

  • MMH Oct 15, 2013 @ 2:48

    It’s better to run this command to update all java commands at once specially for JDK:

    for x in java{,c,p,h,ws}; do update-alternatives --install /usr/bin/$x $x /usr/lib/jvm/java-1.7.0-sun-amd64/bin/$x 1074; done
  • dai Oct 19, 2013 @ 15:00

    where can you get “update-java-alternatives” separately from Ubuntu ?
    anyone ?

  • Kor Oct 29, 2013 @ 7:11

    How do you update, save and close?? I don’t understand Linux commands.

    stuck at “vi -r ~/bashrc”

  • Hrishikesh Feb 20, 2014 @ 13:39

    Thanks :)

  • Biswa Feb 26, 2014 @ 10:57

    Thanks for the article. :)

  • Saurabh Goyal Nov 30, 2015 @ 8:08

    bash: /usr/bin/javac: cannot execute binary file

  • Sug007 Jun 20, 2016 @ 16:21

    Hi Folks,

    Thanks for putting up this article and then few comments especially the one from Brian, was of great help. I was through all the steps but then when i finally wanted to check the java version, i am facing the below error :

    sug007:/etc/alternatives$ java -version
    bash: /usr/bin/java: cannot execute binary file

    In the properties of this java (/usr/bin/java), i see it points to the etc/alternatives/java which in turn points to /usr/lib/jvm/jdk1.8.0_92/bin/java.

    Any help is really appreciated..! Thanks

    • Sug007 Jun 21, 2016 @ 8:51

      Got it Folks. I had used the wrong version of the jdk. I installed the 32-bit version and now everything is fine.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum