How to install Java 7 on Ubuntu 12.04 LTS

Oracle JDK is no longer included by default in Ubuntu’s repositories due to licensing. OpenJDK is default now but many apps still don’t play nice with it. This is why I installed Oracle JDK.

I’ll walk you through the process of installing Oracle JDK 7 on Ubuntu 12.04 LTS Precise Pangolin, the easy way. For this we will use the “install oracle-java7-installer” package from “WEBUPD8″.

The “install oracle-java7-installer” package from “WEBUPD8″ will download the official binaries from Oracle and install the JAVA 7 JDK, JRE and browser plugins on your machine.

1. Add the “WEBUPD8″ PPA.

danesh@python:~$sudo add-apt-repository ppa:webupd8team/java 

2. Update your repositories.

danesh@python:~$sudo apt-get update 

3. Install JAVA 7 JDK.

danesh@python:~$sudo apt-get install oracle-java7-installer

To uninstall,

sudo apt-get remove oracle-java7-installer

Did it work for you? Test here

  • squiglybob13

    Thanks for this tutorial! It was just what I was looking for and it was very easy to follow! Thanks again!

    • http://thedaneshproject.com Danesh

      Glad to help :D

  • Olie

    How do you do this on a usb drive

  • Rickey Moore

    Whoops! It cannot download …downloadfailed from oracle I guess. Ric

  • http://thedaneshproject.com Danesh

    Keep trying a few times.

  • John

    What are the license requirements? I take it’s not compatible with the gpl???

    • http://thedaneshproject.com Danesh

      you’re right. Not GPL.

  • John

    You should also do a tutorial on how-to install the latest net-beans ide on ubuntu. Though I think it is updated more frequently then the programming language it self. Maybe I should write up a tutorial myself. Seeing as I’m doing it lol. I was just being lazy and didn’t want to have to compile it myself. So I used your repository. I might later on a fresh install of ubuntu see if I can install it without any dependencies problems. Anyways great tutorial.

  • Rickey Moore

    Anyone else see this problem?? Suppose this script could just accept the file we’ve already downloaded and correctly install it? I really don’t have to have a script to dnload something. I just need all of my alternatives set correctly. Thanks for the good work! I just think Oracle isn’t going to allow dnloading Java without clicking on the “I agree” button first.

  • Rickey Moore

    Dansesh, I have tried this a bunch of times, in the last few days. I have used this ppa for quite some time and referred it to many people. There is another ppa site that offers something similar, and just recently their users reported it is broken as well. http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html

    So, it might be better to have a post manual install of java application to set the alternatives. Then everyone pays homage to Oracle by paying them a visit and checking the “I agree” button. Ric

  • Stephae

    Worked great for me, thank you.

    Commercial interest are really hurting our world :-(

  • Gary

    Thanks, I was going mad there for a while. Your solution was fantastic

  • Jeff

    Thank YOU!!!

  • Wes

    This tutorial (like most Ubuntu tutorials) starts in the middle. I still have no idea how to install Java 7.

    • http://jrot.slash.kr John Rotten

      How does it start in the middle? This is a step by step guide from the start. If you are too stupid to follow three simple steps, try buying a Windoze PC…

  • Azhar

    Thank you very much.

  • alex peterson

    thank you soooooo much im kinda new to ubuntu and have never messed around with the terminal before once again thank you.

  • zX

    -bash: add-apt-repository: command not found

    I have this error, can anyone help me? :)
    Sorry im realy new in linux, just learning.

    • Mike Stewart

      Try apt-get install python-software-properties and then try the add-apt-repository command again

  • Emilio Merino

    Worked great for me too, excelent, Thank you very much.

  • http://www.jefind.com lenin

    thankyou very much for helping me to install java

  • http://backadesign.com Ivan

    Thanks. It was very helpfull.

  • http://www.justanotherdeveloper.co.uk Gavin

    You need to install python-software-properties in order to run add-apt-repository

    sudo apt-get install python-software-properties

  • Mike Stewart

    Thank you, at last a solution which works! I’d tried more than a dozen others without success.

  • Ric Moore

    Still getting this:
    ric@Iam:~$ sudo apt-get install oracle-java7-installer
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    oracle-java7-installer is already the newest version.
    The following packages were automatically installed and are no longer required:
    libgsoap1 libsieve2-1 tinymce
    Use ‘apt-get autoremove’ to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    1 not fully installed or removed.
    After this operation, 0 B of additional disk space will be used.
    Do you want to continue [Y/n]? y
    Setting up oracle-java7-installer (7u5-0~webupd8~5) …
    Removing outdated cached downloads…
    Downloading cookie…
    –2012-07-25 17:43:02– http://launchpadlibrarian.net/98645053/cookie.txt
    Resolving iam.wayward4now.net (iam.wayward4now.net)… 192.168.0.2
    Connecting to iam.wayward4now.net (iam.wayward4now.net)|192.168.0.2|:3142… connected.
    Proxy request sent, awaiting response… 403 Forbidden file type or location: http://launchpadlibrarian.net/98645053/cookie.txt
    2012-07-25 17:43:02 ERROR 403: Forbidden file type or location: http://launchpadlibrarian.net/98645053/cookie.txt.

    download failed
    Oracle JDK 7 is NOT installed.
    dpkg: error processing oracle-java7-installer (–configure):
    subprocess installed post-installation script returned error exit status 1
    Errors were encountered while processing:
    oracle-java7-installer
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    ric@Iam:~$

    I used to work like a charm, in the past. Thanks! Ric

    • http://thedaneshproject.com Danesh

      Try again Ric. Should work now.

  • HoBBeS

    Thank you so much — I can’t believe you fixed my problem in 3 shell commands…
    (I wasted several hours on it a while ago and gave up)

    Good karma for you, you’re awesome.

    • http://thedaneshproject.com Danesh

      Thanks HoBBes

  • Kjell-Magne Skåden

    Thanks for this tutorial :)

  • amplatfus

    Thank you so much!

  • http://www.opensourcealternative.org Saurabh Bansal

    Its the easiest tutorial to install Java on Ubuntu 12.04. Installed it with ease and its working well without any problems. Thanks so much.

  • Pingback: Compiling ICS for Breakout - Android Forums

  • John Burns

    Tried the instructions and everything seemed to load ok, but testing Java brings up the message that it’s not the updated version. I’ve been struggling to get Java working properly for over a week now (yet it used to work before) Grrrrrr

  • John Burns

    Quick update, when I go to any site that requires Java (using Chrome web browser) I get the message to update the plugin or run this time. Selecting “run this time” does indeed start Java working, but selecting “Update plug in” does absolutely nothing, apart from opening the download page at Java.

  • Gene

    Step 1-Failed=comand not found. Now what?

  • Marcelo Divê

    Thanks! You help me a lot!

  • greenzine

    max@max:/$ sudo apt-get install oracle-java7-installer
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package oracle-java7-installer

  • http://twitter.com/teejurjee Tony Jurjonas

    New installs may not have the python-software-properties package required to execute the add-apt-repository command. If anyone has errors while doing this, run ” sudo apt-get install python-software-properties ” to make the add-apt-repository command work.

  • http://www.facebook.com/alrisa.vortreizen Alrisa VorTreizen

    thank you very much!

  • dinner boy

    it says Error: Must run as root

    • http://thedaneshproject.com Danesh

      use sudo.

  • alina

    This is perfect, thank you!

  • grundic

    Thanks a lot! Works like a charm in Xubuntu 12.04.

  • disqus_yVzAROKQ16

    Thanks for this. It eliminated a Java error msg when running ClearView flight simulator under Ubuntu 12.04LTS

  • joehot200

    sudo: add-apt-repository: command not found

  • Pingback: How to start hadoop programming from scratch: Setting Up | Learning Hadoop

  • http://www.facebook.com/profile.php?id=100005809027416 Emily Taylor

    Thank you SOOO much for this, easy three steps that actually work unlike a lot of ubuntu help, I’m honestly starting to hate this OS

    • http://profiles.google.com/wayward4now Rickey Moore

      It’s just different is all. Yes, you DO have many new options to consider now, but that is just a learning curve. The only alternative is no options at all, Just find and befriend some local starving geeks with a pizza and get some hands on experience.

      • Emily Taylor

        meh debian was better, but anway how do i update the java now its out of date?

  • http://www.facebook.com/profile.php?id=100005809027416 Emily Taylor

    oh btw how do I update java? it say’s it’s out of date and i always to click “run this time” its annoying

  • Martin

    it worked

  • Alexis Saransig

    Very Helpfull :) thanks

    • http://thedaneshproject.com Danesh

      you’re welcome.

  • Paul Hacker

    Will any of this interfear with Apache, PHP, or MySQL (or C++ for that matter.) My test server has all that but I want to add Java. Thanks!