Install Oracle Java JDK 7 in Ubuntu 12.04

Below steps will show you how to install Oracle java jdk 7 in ubuntu 12.04( precise),and here we install oracle JDK 7u4 as an example

1.Download the latest 32bit or 64bit Oracle JDK .tar.gz file from  Oracle JDK Download (*i586.tar.gz and *x64.tar.gz for 32bit and 64bit ubuntuaccordingly )

2.Extract the .tar.gz file to your /usr/lib/jvm directory

sudo mkdir -p /usr/lib/jvm

For 32bit:

sudo tar -xf jdk-7u4-linux-i586.tar.gz -C  /usr/lib/jvm

For 64bit:

sudo tar -xf jdk-7u4-linux-x64.tar.gz -C /usr/lib/jvm

3.Use below commands to install oracle JDK 7 to your system

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.04/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.04/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.04/bin/javaws" 1

4.Use below command to check if you have other old java version installed

java -version
  • If it shows you the correct version which you just downloaded and installed,just go to step 6 to enable firefox  plugin.
  • If it shows you an old or another version of java which is not what you want ,go to step 5

5.Run below commands to active the JDK we just installed.

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

6.Enable firefox plugin

mkdir ~/.mozilla/plugins

For 32 Bit:

ln -sf /usr/lib/jvm/jdk1.7.04/jre/lib/i386/ ~/.mozilla/plugins/

For 64 Bit:

ln -sf /usr/lib/jvm/jdk1.7.04/jre/lib/amd64/ ~/.mozilla/plugins/

7.(Optional)You can verify you have installed oracle Java JDK 7 correctly on This Oracle Page

15 thoughts on “Install Oracle Java JDK 7 in Ubuntu 12.04

  1. Pingback: Install Oracle Java JDK 7 in Ubuntu 12.04

  2. Priyanshu

    thanx a lot
    now if i run the “java -version” command it show the correct version of jdk
    but the link you mentioned to check jdk from oracle site doesn’t work.
    The browser(both mozilla and chromium) ask me to install some “open java plugins”
    what should i do?
    or i can simply use jdk 7 for eclipse or netbeans
    sorry for my poor english

      1. Priyanshu

        yes,problem was in step 6
        i forgot to jdk1.7.04–>jdk1.7.0_05 (in my case)

        ln -sf /usr/lib/jvm/jdk1.7.0_05/jre/lib/amd64/ ~/.mozilla/plugins/

        everywhere else i had changed the jdk version

  3. Kevin Loughrey

    when carrying out the command

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

    I mistyped the j and typed h instead making it “hava” as above. Any remedy? or should I (can I) just live with it. Went to the Oracle page and tested my installation. It came back with a congratulatory message saying JDK7 was properly installed.

    1. Admin Post author


      It’s not a critical type error,you can just live with it.

      also you can correct it use below commands:
      sudo update-alternatives –remove hava “/usr/lib/jvm/jdk1.7.0_05/bin/java”
      sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.7.0_05/bin/java” 1

  4. Abu Sadat

    Hey Admin thanks a lot for your help.
    Well let me know is there any path setting in linux for java as we do in windows. i had installed java 5,6 & 7 together in windows, i do change their concerned path when i need.
    Do you know is there any such stuff here in linux?

  5. jerôme

    hello I have a problem with the command line: ln-sf / usr/lib/jvm/jdk1.7.04/jre/lib/amd64/ ~ /. mozilla / plugins /
    when I go into the terminal it gives me: command not found

  6. Ankit Shah

    The tutorial’s just flawless and awesome.
    Thank you.
    Can you help me getting it configured for chromium browser as you did for firefox.


Leave a Reply

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