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.

This question already has an answer here:

Most of the software is not thoroughly tested with Java 7 and I would like to install Oracle's JDK 6.0 on Ubuntu 11.10.

Could someone please provide me the instructions for the same?

share|improve this question

marked as duplicate by guntbert, minerz029, Eric Carvalho, mikewhatever, Florian Diesch Jan 26 at 17:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

11 Answers 11

up vote 78 down vote accepted

Due to license issues Ubuntu will no longer distribute Oracle's JDK and JRE. Also previous versions supplied on PPAs suffer from security issues are are not recommended to be installed on any Ubuntu system.

There are no more supported java releases from Ubuntu - Ubuntu officially supports OpenJDK and OpenJRE implementation of Java which is the base for Oracle's own implementation.

To install the OpenJDK & OpenJRE refer to this Q&A.

The instructions below provide a guide to install the official Oracle JDK 6. You will need to regularly update this manually to ensure your installation maintains recommended security and stability fixes.

Install the Oracle JDK 6

Oracle JDK 6 is no longer maintained. It is not updated with the latest security patches and are not recommended for use in production.
You can however still download them from the Oracle Java Archive

Oracle themselves have the official guide to install their JDK - below is based upon those instructions.

  • Download the 32bit or 64bit Linux "compressed binary file" - it has a ".bin" file extension
  • Give it permissions to execute and extract it

    chmod a+x [version]-linux-i586.bin

    ./[version]-linux-i586.bin

During installation it will ask you to register - press ENTER. Firefox will open with the registration page. Registration is optional.

JDK 6 package is extracted into ./jdk1.6.0_x directory, for example ./jdk1.6.0_30.

Lets rename it:

mv jdk1.6.0_30 java-6-oracle
  • Now move the JDK 6 directory to /usr/lib

sudo mkdir /usr/lib/jvm

sudo mv java-6-oracle /usr/lib/jvm

switch to Oracle JDK 6

webupd8.googlecode.com hosts a nice-easy script to help with this.

wget http://webupd8.googlecode.com/files/update-java-0.5b
chmod +x update-java-0.5b
sudo ./update-java-0.5b

don't worry - 0.5b refers to the script version - not the version of java!

An alternative to this is to use the webupd8 ppa and the update-java package.

enter image description here

Finally test the switch has been successful:

java -version
javac -version

These should display the oracle version installed - 1.6.0_30

Install the Firefox/Chrome plugin

In a terminal:

mkdir ~/.mozilla/plugins

Remove the IcedTea plugin, if it has been installed.

sudo apt-get remove icedtea6-plugin

Remove a former version of the Java plugin (may or may not be present)

rm ~/.mozilla/plugins/libnpjp2.so

Now you can install the plugin, by creating a symbolic link (you tell Firefox, where the plugin is located).

(32bit)

ln -s /usr/lib/jvm/java-6-oracle/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

(64bit)

ln -s /usr/lib/jvm/java-6-oracle/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Confirm that the JRE has been successful by using the official oracle website.


Linked Questions:

  1. How do I install Java?
  2. How do I install Oracle Java JDK 7?
  3. How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE?
share|improve this answer
2  
nice and easy :) –  Praveen Sripati Jan 12 '12 at 1:58
3  
@MPi - I would also echo Brunos comment - there is no longer a "sun" or an "oracle" package '/usr/lib/jvmc is where all the other implementations of java will go, besides, the naming of the folder where we are keeping oracle's jdk is custom, no package will overwrite it, and if it does there will be no problem since it will do the same as it was done here. there is really no reason what so ever that this is not close to a system wide installation of oracle's jdk. if you have any further suggestions please do so, but there is nothing wrong with the paths used here –  fossfreedom Jan 12 '12 at 9:32
    
@fossfreedom the plugin part works for me!! –  Matteo Apr 13 '12 at 13:27
    
The update-java package/script does not seem to contain oracle packages anymore, but one can use "sudo add-apt-repository ppa:webupd8team/java" and "sudo apt-get install oracle-java6-installer" –  Radu Maris Oct 9 '13 at 13:16
    
Before the step about webupd8, make sure that gksu is installed on your system. –  Fredrick Gauss Jun 25 at 5:21

Since Oracle Java has been removed from the repository, you will have to add a new repository like mentioned in this article. The repository described there has also packages for Oneiric.

Note: It's important to trust the repository/ppa you're installing from.

This could do anything.

So, if you trust the repository and developer below;

Open up a terminal window under Application -> Accessories -> Terminal, adding the ppa > by:

sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update

Then, install java jre:

sudo apt-get install sun-java6-jre sun-java6-jre-plugin

Install Jdk by the command:

sudo apt-get install sun-java6-jdk
share|improve this answer

I used the following instruction by downloading the jdk binaries directly from Oracle. The instructions apply for jdk6 also.

share|improve this answer

I expect, that the ppa of ferramroberto might not be working in the future, because repackaging of java is not allowed any more. Unfortunately what is not allowed for canonical is also not allowed for any other packager. So the solution mentioned above might be the only way (which is basically a wrapper for update-alternatives!):

http://www.webupd8.org/2011/09/how-to-install-oracle-java-7-jdk-in.html

It is generally a good idea, to get an oracle account and get the java newsletter to be informed about software updates until a solution comes along the way for us ubuntu users to be informed about updates.

share|improve this answer
    
I follow up the instructions in the link above, so I actually follow this link: webupd8.org/2012/01/… and it work, really easy, should try. Upvote –  rob.alarcon Aug 4 '12 at 23:36

The reason why Oracle's Java implementation is not supported or distributed by Ubuntu already discussed here.

The basic idea is that Oracle's Java Se will not be included in any official Ubuntu repo due to license problems created by Oracle.

That does not stop you from installing Oracle's JDK from a PPA or from the official package files from the Oracle's site.

This guide describes how-to download, install and make java, javac and javaws from Oracle available to use in your system.

How to install Oracle Java JDK6u30 on Ubuntu 11.10

(should work with any other version downloaded from Oracle)

  • Download Sun/Oracle Java JDK

Download Sun/Oracle Java JDK or JRE from here (current version is JDK 6 Update 30) http://www.oracle.com/technetwork/java/javase/downloads/index.html.

Note: Select any of the Linux x86 or Linux x64 bin packages (example jdk-6u30-linux-i586.bin, jdk-6u30-linux-x64.bin) depending on your system and preference.

  • Make the file executable

chmod +x /path/to/file/jdk-6u30-linux-*.bin

  • Run Sun/Oracle Java JDK binary and delete it

/path/to/binary/jdk-6u30-linux-*.bin && rm /path/to/binary/jdk-6u30-linux-*.bin

There will be a newly created folder on the same path with the extracted files

  • Move the folder to a system wide path and give it a more identifiable name
mkdir -p /usr/lib/jvm
cd /path/to/binary/
mv /path/to/binary/jdk1.6.0_30 /path/to/binary/java-6-oracle && mv /path/to/binary/java-6-oracle /usr/lib/jvm/


  • Add the new version of java, javac and javaws as an system alternative and give it priority 1
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-6-oracle/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6-oracle/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-6-oracle/bin/javaws" 1
  • Select the new alternatives to be used
sudo update-alternatives --config java

Select your created java alternative

sudo update-alternatives --config javac

Select your newly created javac alternative

sudo update-alternatives --config javaws

Select your new created javaws alternative

  • Test your newly added java and javac

java -version should return

java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

and javac -version should return

javac 1.6.0_30
  • Update system paths

Open /etc/profile with you favorite text editor, ie

gksudo gedit /etc/profile

Navigate to the end of the file and add these contents

JAVA_HOME=/usr/lib/jvm/java-6-oracle
JAVA_BIN=$JAVA_HOME/bin
PATH=$PATH:$JAVA_HOME:$JAVA_BIN
export JAVA_HOME
export JAVA_BIN
export PATH

Reload your system wide PATH /etc/profile with

. /etc/profile

That is for Oracle's JDK, java, javac and javaws should be running from the Oracle's package.

The version here installed can be updated easily by copying the new version over the currently installed files. Just extract the package and copy over the new one over the one that is currently installed.

You might want to check /etc/alternatives for links to older installs of JRE - there are many tools that might not be found on your system after a manual install like this.

share|improve this answer
5  
-1 for suggesting to put the JDK under /usr/lib. It is a bad idea to put anything there by yourself, this area is expected to be handled by the packaging system. –  MPi Jan 12 '12 at 8:07
3  
@MPi there is no longer a "sun" or a "oracle" pacakage '/usr/lib/jvmc is where all the other implementations of java will go, besides, the naming of the folder where we are keeping oracle's jdk is custom, no package will overwrite it, and if it does there will be no problem since it will do the same as it was done here. there is really no reason what so ever that this is not close to a system wide installation of oracle's jdk. if you have any further sugestions please do so, but there is nothing wrong with the paths used here. –  Bruno Pereira Jan 12 '12 at 9:27
3  
There is no Oracle Java now, but there may be in the future. But this is beside the point. Locally installed software should not go into the folders that are handled by the packaging system. There is /opt or /usr/local for precisely this use case; see also wiki.debian.org/FilesystemHierarchyStandard –  MPi Jan 12 '12 at 13:16
3  
Thanks for detailed instructions!! Saved the day! –  Tauquir Aug 8 '12 at 18:41
    
So when I follow your instructions update-java-alternatives does not see the newly installed Oracle JDK. Is there anyway to synchronize update-java-alternatives with update-alternatives? –  James McMahon Dec 13 '12 at 19:35

In many cases it is not necessary to switch over to Oracle Java (or any other alternative version) completely. Many applications that require something other than the standard Java version can be started by explicitely calling the required Java VM:

<path to alternative JRE>/bin/java -jar <application>.jar

Perhaps JAVA_HOME should also be explicitely set before starting the application:

export JAVA_HOME=<path to alternative JRE>
share|improve this answer

There is very good page on official Ubuntu wiki. There you can find all recommended methods. I've used this excellent automatic script.

cd ~/
wget https://github.com/flexiondotorg/oab-java6/raw/0.2.6/oab-java.sh -O oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh

Script will build packages from source and place them in local repo, then they can be installed e.g.:

sudo apt-get install sun-java6-jdk sun-java6-fonts sun-java6-source

You can see all available packages in /var/local/oab/deb.

Remember to select the right version:

sudo update-alternatives --config java

To setup everything else (like browser plugin, keytool, etc.) you can use this (it will be a long list!):

sudo update-alternatives --all

The script is a wrapper for this Debian script, if you're curious ;)

share|improve this answer

Oracle now owns Sun, and has renamed it to Oracle Java. If you want to install the latest version of Java 6, you can download it here:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

The binary file is a self-extracting archive. Copy it to where you want to install it, e.g. /opt/java

Then create a link,

# update-alternatives /usr/bin/java java /opt/java/bin/java 0

Do the same for javac if necessary.

share|improve this answer

Run this command in a terminal (Ctrl+Alt+T):

sudo add-apt-repository ppa:ferramroberto/java
  • If you get this error:

    sudo add-apt-repository command not found 
    
  • Then install it by:

    sudo apt-get install python-software-properties
    
  • And then run that command again:

    sudo add-apt-repository ppa:ferramroberto/java
    

Then do:

sudo apt-get update
sudo apt-get install sun-java6-jdk

It worked fine for me.

share|improve this answer
    
This is not a good way to install Java, because that PPA only provides very old versions, which have major shortcomings including serious security bugs. Oracle changed the licensing terms for the proprietary Java JRE and JDK so that it cannot be freely redistributed in this way. So there's no PPA anymore that provides safe, up-to-date Java. A full explanation, with citations, of what version the PPA is able to provide and why, cannot fit into a comment. But if you post a new question about that and ping me here (with @EliahKagan), I'll try to answer it. –  Eliah Kagan Oct 11 '12 at 10:24

Hi check out this very detailed explanation of how to install java jdk on your pc and test it http://www.pavanh.com/2013/03/installing-java-jdk.html

share|improve this answer
    
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  David Edwards Jul 7 '13 at 8:07

Open the terminal and execute below commands one by one. It will install JDk as well as JRE. No need to configure anything. It will take care of everything.

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

JDK 6 along with JRE

sudo apt-get install oracle-java6-installer

OR FOR JDK 7

sudo apt-get install oracle-java7-installer

Once executed you can check, whether the Java and JDK is installed by java -version and then javac -version

share|improve this answer

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