Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I install Java on Ubuntu 12.04?

I have:

  • Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
  • Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
share|improve this question

4 Answers 4

To install the latest version of Oracle Java (the latest posted in the Oracle webpage), the easiest way is to use the Java Installer (as flashplugin-installer does) as here is explained: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

Oracle JDK7 itself is not hosted in the PPA because that's not allowed by the new Java license (which is also the reason why it has been removed from the official Ubuntu repositories); the package in the PPA automatically downloads (and installs) Oracle Java JDK 7 from its official website and installs it on your computer, just like the flashplugin-installer package does.

Then, you have to do only this:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

And type this to check the version:

java -version
share|improve this answer
4  
Should be the accepted answer. –  blo0p3r Dec 11 '13 at 20:44
3  
Note that on a stock 12.04 install, add-apt-repository is not available. To solve this, run sudo apt-get install python-software-properties. –  Duncan Dec 23 '13 at 14:31

PPA are not a secure / smart way of installing something. Installing JDK is very simple and straightforward.

The Steps are as followed:

Download latest jdk from Oracle's site and extract:

tar -xvf jdk-7u51-linux-x64.tar.gz
mkdir -p /usr/lib/jvm
mv ./jdk1.7.0_51/ /usr/lib/jvm/jdk1.7.0_51/

Create some symbolic links:

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

Similarly, symbolic links can be created for other commands of JAVA. Other available commands are:

appletviewer,apt,extcheck,idlj,jar,jarsigner,javadoc,javafxpackager,javah,javap,java-rmi.cgi,jcmd,jconsole,jcontrol,jdb,jhat,jinfo,jmap,jmc,jps,jrunscript,jsadebugd,jstack,jstat,jstatd,jvisualvm,keytool,native2ascii,orbd,pack200,policytool,rmic,rmid,rmiregistry,schemagen,serialver,servertool,tnameserv,unpack200,wsgen,wsimport,xjc

Ensure right users have the right permission:

sudo chmod a+x /usr/bin/java 
sudo chmod a+x /usr/bin/javac 
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.7.0

Reference: Coders of tHe Dark | Blog

share|improve this answer
    
PPAs can indeed be dangerous. But they can also be smart and more secure than a direct download, in the sense that they automate the process of upgrading. If the people running the ppa are trustworthy, and they sign their packages etc, then they are a good alternative to having people check the checksums of the tar.gz themselves, do the intstalls, and then constantly watch for notice of the need for a security update, and do it all over again. Note also that the ppa package does a number of other "update-alternatives" calls, for various installed programs that use java. –  nealmcb Jun 1 at 22:30

As said above installing from that PPA is the easiest way to do it. Though it might take a day or two for it to be updated to the newest version 7u25. If the problem you experience is a pop-up window saying "Application blocked by security settings", and you really need to use java right now, you can bypass it by decreasing you security level for java. Go to your menu -> preferences -> Oracle java 7 plugin control panel. In there open the security tab, and move the slider to "medium", and apply. That should do the trick.

Hope it helps.

share|improve this answer

If you get error message like couldn't resolve host 'launchpad.net' and you sure your proxy server settings are correct (http_proxy and https_proxy) try sudo -E add-apt-repository ppa:tualatrix/ppa

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.