577

I want to install Oracle's JRE and to update to the latest version with the Software Updater when they released. Is there a Ubuntu package that is provided by Canonical or Oracle?

Before release Java 7, I followed this way to install Java 6.

But it doesn't work for Java 7. There is no package sun-java7-xxx. How can you install Java 7?

10
  • 2
    I wrote a blog post with a very detailed explanation on how to install Java 7 on Natty, both OpenJDK's and Sun's: http://brunoreis.com/tech/installing-java-ubuntu-natty/ OpenJDK is installed from the PPA provided by Damien Lecan, and Sun's is installed manually. As far as know, until now that is the only guide that is correct both in the steps and the explanation. If you find any problems, post a comment there and I will try to fix it. Good luck.
    – Bruno Reis
    Aug 17, 2011 at 18:48
  • 12
    I would also like to point out that using OpenJDK is more than a viable alternative: it is also the reference implementation now. Nov 12, 2012 at 16:40
  • 12
    openJdk is not supported by banks applets or by other software. example: Aptana Studio Mar 14, 2013 at 19:34
  • 4
    link to "this way" seems to reveal...no description of a way?
    – rogerdpack
    Jan 31, 2014 at 17:35
  • 1
    @GKFX no, for this specific bank IcedTea was not working and the bank was supporting only Oracle's Java. Meanwhile they quit using Java and I think it was a wise decision. Apr 8, 2015 at 20:53

28 Answers 28

905

There is a similar answer on how to install JRE 7.

Install Java JDK

The manual way

  • Download the 32-bit or 64-bit Linux "compressed binary file" - it has a ".tar.gz" file extension.

  • Uncompress it

    tar -xvf jdk-8-linux-i586.tar.gz (32-bit)

    tar -xvf jdk-8-linux-x64.tar.gz (64-bit)

    The JDK 8 package is extracted into ./jdk1.8.0 directory. N.B.: Check carefully this folder name since Oracle seem to change this occasionally with each update.

  • Now move the JDK 8 directory to /usr/lib

    sudo mkdir -p /usr/lib/jvm
    sudo mv ./jdk1.8.0 /usr/lib/jvm/
    
  • Now run

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

    This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.

  • Correct the file ownership and the permissions of the executables:

    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.8.0
    

    N.B.: Remember - Java JDK has many more executables that you can similarly install as above. java, javac, javaws are probably the most frequently required. This answer lists the other executables available.

  • Run

    sudo update-alternatives --config java
    

    You will see output similar to the one below - choose the number of jdk1.8.0 - for example 3 in this list (unless you have have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):

    $ sudo update-alternatives --config java
    There are 3 choices for the alternative java (providing /usr/bin/java).
    
      Selection    Path                                            Priority   Status
    ------------------------------------------------------------
      0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
      1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
    * 2            /usr/lib/jvm/jdk1.7.0/bin/java                   1         manual mode
      3            /usr/lib/jvm/jdk1.8.0/bin/java                   1         manual mode
    
    Press enter to keep the current choice[*], or type selection number: 3
    update-alternatives: using /usr/lib/jvm/jdk1.8.0/bin/java to provide /usr/bin/java (java) in manual mode
    

    Repeat the above for:

    sudo update-alternatives --config javac
    sudo update-alternatives --config javaws
    

Note for NetBeans users!

You need to set the new JDK as default editing the configuration file.


If you want to enable the Mozilla Firefox plugin:

32 bit:
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

64 bit:
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

N.B.: You can link the plugin (libnpjp2.so) to /usr/lib/firefox/plugins/ for a system-wide installation (/usr/lib/firefox-addons/plugins from 15.04 onwards). For Ubuntu 13.10, the path to the plugin directory is /usr/lib/firefox/browser/plugins/.

Depending on your configuration, you might need to update the apparmor profile for Firefox (or other browsers) in /etc/apparmor.d/abstractions/ubuntu-browsers.d/java:

# Replace the two lines:
#  /usr/lib/jvm/java-*-sun-1.*/jre/bin/java{,_vm} cx -> browser_java,
#  /usr/lib/jvm/java-*-sun-1.*/jre/lib/*/libnp*.so cx -> browser_java,
# with those (or adapt to your new jdk folder name)
/usr/lib/jvm/jdk*/jre/bin/java{,_vm} cx -> browser_java,
/usr/lib/jvm/jdk*/jre/lib/*/libnp*.so cx -> browser_java,

Then restart apparmor:

sudo /etc/init.d/apparmor restart

The easy way (Obsolete)

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of hostorical reasons.

The easiest way to install the JDK 7 is to do it with the Web Up8 Oracle Java OOS. However, it is believed that this PPA is sometimes out of date. Also note the dangers of using a PPA.

This installs JDK 7 (which includes Java JDK, JRE and the Java browser plugin):

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
# or if you want JDK 8:
# sudo apt-get install oracle-java8-installer
# these commands install Oracle JDK7/8 and set them as default VMs automatically:
# sudo apt-get install oracle-java7-set-default
# sudo apt-get install oracle-java8-set-default

Source

N.B.: Before someone screams this is against the Oracle redistribution license - the PPA does not actually have Java in the personal repository. Instead, the PPA directly downloads from Oracle and installs it.

The Script way

If you're on a fresh installation of Ubuntu with no previous Java installations, this script automates the process outlined above if you don't want to type all that into a console. Remember, you still need to download Java from Oracle's website -- Oracle's links are not wget friendly.

Before using this make sure that this script is in the same directory as the .tar.gz file extension that you downloaded and there are no files that start with jdk-7 in the same folder. If there are, please move them out of the folder temporarily. Remember to make the script executable (chmod +x <script's file>).

#!/bin/sh

tar -xvf jdk-7*
sudo mkdir /usr/lib/jvm
sudo mv ./jdk1.7* /usr/lib/jvm/jdk1.7.0
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws

If you want to install the plugin for Firefox then add this to the end of the script:

mkdir ~/.mozilla/plugins
ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/
sudo /etc/init.d/apparmor restart

Check if installation was successful

You can check if the installation succeeded with the following command:

java -version

You should see something like

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

You can check if the JRE Mozilla plugin has been successful by using the official oracle website.


For Java 6: How do I install Oracle JDK 6?

15
  • 8
    Is necessary to do all the same process to update it?
    – Lucio
    May 24, 2013 at 15:50
  • 6
    This worked successfully for me installing the 32-bit JDK on Ubuntu 12.04LTS, except that I was getting bash: /usr/bin/java: No such file or directory when I tried to run java -version. apt-get install libc6-i386 fixed the problem.
    – gregmac
    Jul 31, 2013 at 20:57
  • 4
    I suggest the use /usr/local/* in place of /usr/* for any manual installation like here. That way what you install manually wont clutter up with stuff managed by package manager and make manual installation more manageable
    – Flint
    May 1, 2014 at 5:59
  • 4
    I strongly recommend the manual way out of this. It is the most reliable. The PPA doesn't work anymore since Oracle Java is licensed. And the script above assumes you are using the compiler and the runtime and that version on it is out of date. Jul 18, 2014 at 18:44
  • 1
    How can I install manpage?
    – Tim
    Oct 9, 2014 at 1:02
172

There is a similar answer on how to install JDK 8

Install the JRE

Download the 32-bit or 64-bit Linux "compressed binary file" - it has a ".tar.gz" file extension and uncompress it

tar -xvf jre-7-linux-i586.tar.gz

The JRE 7 package is extracted into ./jre1.7.0 directory. Now move the JRE 7 directory to /usr/lib:

sudo mv ./jre1.7.0* /usr/lib/jvm/jre1.7.0

Afterwards, run the following to get a list of currently installed Java alternatives.

sudo update-alternatives --config java

You will get output as:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode

Press enter to keep the current choice[*], or type selection number:

Remember the last number and press enter to exit this utility i.e. in this example remember the number 2.

If only one alternative is shown then remember the number 0.

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.7.0/bin/java 3

This will add your new JRE 7 installation into the alternatives list i.e. use the remembered number + 1, that is, 3 in the example above. Now configure Java to use the Oracle Java JRE:

sudo update-alternatives --config java

You will see output similar one below - choose the number of jre1.7.0, that is, 3:

There are 3 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
3 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode

Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jre1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.

N.B.: If there was no previous Java installation then the new JRE will be the default and you will not see the above.

Check the version of you new JRE 7 installation:

java -version

It should produce

java version “1.7.0”
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)

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). For 32-bit Java use

ln -s /usr/lib/jvm/jre1.7.0/lib/i386/libnpjp2.so ~/.mozilla/plugins/

For 64-bit Java use

ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

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

15
  • 10
    After running sudo update-alternatives --config java, I get the following output:There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk/jre/bin/java Nothing to configure. What am I doing wrong?
    – Shoan
    Mar 18, 2012 at 4:56
  • 7
    great answer, thanks! Wonder why Oracle can't spend the time to make packages for this.... Mar 26, 2012 at 22:11
  • 1
    @Shoan, in that case, go to step "if only one alternative is shown then remember the number 0"
    – henrique
    Mar 27, 2012 at 1:57
  • 3
    Thank you for this answer, Oracles instructions are rubbish for a linux noob, this made things alot easier! May 9, 2012 at 9:33
  • 1
    While this method works - apt-get won't know that you have java installed. So trying to install tools like ant, maven, etc will still want to install openjdk. Instead something like webupd8.org/2012/01/… worked great for me!
    – Brad
    May 7, 2013 at 21:31
99
+250

Here is a tested and working solution for installing Oracle JDK 7 and all its files so "javac" and everything else works: How To Install Oracle Java 7 (JDK) In Ubuntu

Here are the commands (just for convenience):

  1. Download the latest Oracle JDK 7 from here.
  2. Extract the downloaded Oracle Java JDK archive in your home folder - a new folder called "jdk1.7.0_03" (for Java JDK7 update 3) should be created. Rename it to "java-7-oracle" and move it to /usr/lib/jvm using the following commands:
cd
sudo mkdir -p /usr/lib/jvm/      #just in case
sudo mv java-7-oracle/ /usr/lib/jvm/

3. Install Update Java package created by Bruce Ingalls (packages available for Ubuntu 11.10, 11.04, 10.10 and 10.04):

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install update-java

4. Now run the following command in a terminal to install Oracle Java JDK:

sudo update-java

Select the Java Version that you want to install and set as the default

After a few minutes, Oracle Java JDK should be successfully installed on your Ubuntu machine. You can check out the version by running these commands in a terminal:

java -version
javac -version

NOTICE! This part below here of this answer no longer works due to Java changing how their binaries are released. It has been left as-is for historical reasons.

Update Oracle has released Java 8 (stable). To install it, use the following commands:

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

More information @ WebUpd8: Install Oracle Java 8 In Ubuntu Via PPA Repository [JDK8]

6
  • I think this script would work for Gnome (tools) but requires a lot of additional installs as for Kubuntu machine (eg. missing gksudo on Kubuntu).
    – Marcin Gil
    Jan 12, 2012 at 9:36
  • good and relatively painless solution on Precise, just installed jdk1.7.0_03 on it
    – prusswan
    Feb 24, 2012 at 6:55
  • I just used this method to put jdk1.7.0_03 on Precise beta 2, as well. It worked, although an error was reported (in Zenity, evidently); the error doesn't appear to have affected the result.
    – Kelley
    Apr 20, 2012 at 16:28
  • 1
    tried it on ubuntu 13.04 and it works. +1 thanks Sep 8, 2013 at 2:33
  • 1
    Add the information that, if we don't want to remove any existing jdk, then we should skip the first dialog which delete existing jdk
    – Anwar
    Dec 12, 2014 at 10:08
94

NOTICE! This solution no longer works due to Java changing how their binaries are released. As a result, this answer is no longer valid. It has been left as-is for historical reasons.

From http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html :

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-jdk7-installer
8
  • 15
    I am wondering why most people are tempted to use the first answer, which is quite complex and requires a lot of manual work, like downloading the installer on your machine and moving it to the server. Your answer is simple and effective!!! TX
    – sorin
    Jul 25, 2012 at 15:02
  • 4
    @SorinSbarnea Some people don't like to use third party repositories because they aren't always updated or online for that matter. Aug 27, 2012 at 21:30
  • On Ubuntu server, I had to use "sudo apt-get install python-software-properties" to get the add-apt-repository command. Mar 13, 2013 at 7:11
  • @SorinSbarnea because the repository is generally well out of date
    – dstarh
    Apr 22, 2013 at 15:31
  • 1
    Note that that Webupd8 PPA also contains a script which will set Oracle Java as default (useful if you have multiple JRE's / JDKs installed), install it with sudo apt-get install oracle-java8-set-default. Also note that this answer is a bit out of date, you should probably be installing oracle-java8-installer these days. Jun 8, 2016 at 13:31
40

This is how I installed it in Oneiric just now. It will be a rather lengthy answer, but it worked for me.

Download latest Java SDK 1.7.0 from Oracle. Then extract it to /usr/lib/jvm:

cd /usr/lib/jvm/
sudo tar -xvzf ~/jdk-7-linux-x64.tar.gz
sudo mv jdk1.7.0 java-7-oracle
sudo ln -s java-7-oracle java-1.7.0-oracle

After that I created .java-1.7.0-oracle.jinfo file in /usr/lib/jvm with the following contents:

alias=java-7-oracle
priority=100
section=non-free

jre ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-7-oracle/jre/bin/java
jre java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-7-oracle/jre/bin/jcontrol
jre keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool
jre pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200
jre policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool
jre rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200
jre orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd
jre servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool
jre tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv
jre jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer
jdk apt /usr/lib/jvm/java-7-oracle/bin/apt
jdk extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck
jdk idlj /usr/lib/jvm/java-7-oracle/bin/idlj
jdk jar /usr/lib/jvm/java-7-oracle/bin/jar
jdk jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner
jdk java-rmi.cgi /usr/lib/jvm/java-7-oracle/bin/java-rmi.cgi
jdk javac /usr/lib/jvm/java-7-oracle/bin/javac
jdk javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc
jdk javah /usr/lib/jvm/java-7-oracle/bin/javah
jdk javap /usr/lib/jvm/java-7-oracle/bin/javap
jdk jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole
jdk jdb /usr/lib/jvm/java-7-oracle/bin/jdb
jdk jhat /usr/lib/jvm/java-7-oracle/bin/jhat
jdk jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo
jdk jmap /usr/lib/jvm/java-7-oracle/bin/jmap
jdk jps /usr/lib/jvm/java-7-oracle/bin/jps
jdk jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd
jdk jstack /usr/lib/jvm/java-7-oracle/bin/jstack
jdk jstat /usr/lib/jvm/java-7-oracle/bin/jstat
jdk jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd
jdk native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii
jdk rmic /usr/lib/jvm/java-7-oracle/bin/rmic
jdk schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen
jdk serialver /usr/lib/jvm/java-7-oracle/bin/serialver
jdk wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen
jdk wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport
jdk xjc /usr/lib/jvm/java-7-oracle/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so

Then you need to tell update-alternatives about all the new stuff:

$ sudo -sH
Password:
# update-alternatives --quiet --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
# update-alternatives --quiet --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
# update-alternatives --quiet --install /usr/bin/appletviewer appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer 100 --slave /usr/share/man/man1/appletviewer.1 appletviewer.1 /usr/lib/jvm/java-7-oracle/man/man1/appletviewer.1
# update-alternatives --quiet --install /usr/bin/apt apt /usr/lib/jvm/java-7-oracle/bin/apt 100 --slave /usr/share/man/man1/apt.1 apt.1 /usr/lib/jvm/java-7-oracle/man/man1/apt.1
# update-alternatives --quiet --install /usr/bin/extcheck extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck 100 --slave /usr/share/man/man1/extcheck.1 extcheck.1 /usr/lib/jvm/java-7-oracle/man/man1/extcheck.1
# update-alternatives --quiet --install /usr/bin/idlj idlj /usr/lib/jvm/java-7-oracle/bin/idlj 100 --slave /usr/share/man/man1/idlj.1 idlj.1 /usr/lib/jvm/java-7-oracle/man/man1/idlj.1
# update-alternatives --quiet --install /usr/bin/jar jar /usr/lib/jvm/java-7-oracle/bin/jar 100 --slave /usr/share/man/man1/jar.1 jar.1 /usr/lib/jvm/java-7-oracle/man/man1/jar.1
# update-alternatives --quiet --install /usr/bin/jarsigner jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner 100 --slave /usr/share/man/man1/jarsigner.1 jarsigner.1 /usr/lib/jvm/java-7-oracle/man/man1/jarsigner.1
# update-alternatives --quiet --install /usr/bin/javac javac /usr/lib/jvm/java-7-oracle/bin/javac 100 --slave /usr/share/man/man1/javac.1 javac.1 /usr/lib/jvm/java-7-oracle/man/man1/javac.1
# update-alternatives --quiet --install /usr/bin/javadoc javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc 100 --slave /usr/share/man/man1/javadoc.1 javadoc.1 /usr/lib/jvm/java-7-oracle/man/man1/javadoc.1
# update-alternatives --quiet --install /usr/bin/javah javah /usr/lib/jvm/java-7-oracle/bin/javah 100 --slave /usr/share/man/man1/javah.1 javah.1 /usr/lib/jvm/java-7-oracle/man/man1/javah.1
# update-alternatives --quiet --install /usr/bin/javap javap /usr/lib/jvm/java-7-oracle/bin/javap 100 --slave /usr/share/man/man1/javap.1 javap.1 /usr/lib/jvm/java-7-oracle/man/man1/javap.1
# update-alternatives --quiet --install /usr/bin/jconsole jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole 100 --slave /usr/share/man/man1/jconsole.1 jconsole.1 /usr/lib/jvm/java-7-oracle/man/man1/jconsole.1
# update-alternatives --quiet --install /usr/bin/jdb jdb /usr/lib/jvm/java-7-oracle/bin/jdb 100 --slave /usr/share/man/man1/jdb.1 jdb.1 /usr/lib/jvm/java-7-oracle/man/man1/jdb.1
# update-alternatives --quiet --install /usr/bin/jhat jhat /usr/lib/jvm/java-7-oracle/bin/jhat 100 --slave /usr/share/man/man1/jhat.1 jhat.1 /usr/lib/jvm/java-7-oracle/man/man1/jhat.1
# update-alternatives --quiet --install /usr/bin/jinfo jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo 100 --slave /usr/share/man/man1/jinfo.1 jinfo.1 /usr/lib/jvm/java-7-oracle/man/man1/jinfo.1
# update-alternatives --quiet --install /usr/bin/jmap jmap /usr/lib/jvm/java-7-oracle/bin/jmap 100 --slave /usr/share/man/man1/jmap.1 jmap.1 /usr/lib/jvm/java-7-oracle/man/man1/jmap.1
# update-alternatives --quiet --install /usr/bin/jps jps /usr/lib/jvm/java-7-oracle/bin/jps 100 --slave /usr/share/man/man1/jps.1 jps.1 /usr/lib/jvm/java-7-oracle/man/man1/jps.1
# update-alternatives --quiet --install /usr/bin/jrunscript jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript 100 --slave /usr/share/man/man1/jrunscript.1 jrunscript.1 /usr/lib/jvm/java-7-oracle/man/man1/jrunscript.1
# update-alternatives --quiet --install /usr/bin/jsadebugd jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd 100 --slave /usr/share/man/man1/jsadebugd.1 jsadebugd.1 /usr/lib/jvm/java-7-oracle/man/man1/jsadebugd.1
# update-alternatives --quiet --install /usr/bin/jstack jstack /usr/lib/jvm/java-7-oracle/bin/jstack 100 --slave /usr/share/man/man1/jstack.1 jstack.1 /usr/lib/jvm/java-7-oracle/man/man1/jstack.1
# update-alternatives --quiet --install /usr/bin/jstat jstat /usr/lib/jvm/java-7-oracle/bin/jstat 100 --slave /usr/share/man/man1/jstat.1 jstat.1 /usr/lib/jvm/java-7-oracle/man/man1/jstat.1
# update-alternatives --quiet --install /usr/bin/jstatd jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd 100 --slave /usr/share/man/man1/jstatd.1 jstatd.1 /usr/lib/jvm/java-7-oracle/man/man1/jstatd.1
# update-alternatives --quiet --install /usr/bin/native2ascii native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii 100 --slave /usr/share/man/man1/native2ascii.1 native2ascii.1 /usr/lib/jvm/java-7-oracle/man/man1/native2ascii.1
# update-alternatives --quiet --install /usr/bin/rmic rmic /usr/lib/jvm/java-7-oracle/bin/rmic 100 --slave /usr/share/man/man1/rmic.1 rmic.1 /usr/lib/jvm/java-7-oracle/man/man1/rmic.1
# update-alternatives --quiet --install /usr/bin/schemagen schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen 100 --slave /usr/share/man/man1/schemagen.1 schemagen.1 /usr/lib/jvm/java-7-oracle/man/man1/schemagen.1
# update-alternatives --quiet --install /usr/bin/serialver serialver /usr/lib/jvm/java-7-oracle/bin/serialver 100 --slave /usr/share/man/man1/serialver.1 serialver.1 /usr/lib/jvm/java-7-oracle/man/man1/serialver.1
# update-alternatives --quiet --install /usr/bin/wsgen wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen 100 --slave /usr/share/man/man1/wsgen.1 wsgen.1 /usr/lib/jvm/java-7-oracle/man/man1/wsgen.1
# update-alternatives --quiet --install /usr/bin/wsimport wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport 100 --slave /usr/share/man/man1/wsimport.1 wsimport.1 /usr/lib/jvm/java-7-oracle/man/man1/wsimport.1
# update-alternatives --quiet --install /usr/bin/xjc xjc /usr/lib/jvm/java-7-oracle/bin/xjc 100 --slave /usr/share/man/man1/xjc.1 xjc.1 /usr/lib/jvm/java-7-oracle/man/man1/xjc.1
# update-alternatives --quiet --install /usr/bin/java-rmi.cgi java-rmi.cgi /usr/lib/jvm/java-7-oracle/bin/java-rmi.cgi 100
# update-alternatives --quiet --install /usr/bin/ControlPanel ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel 100
# update-alternatives --quiet --install /usr/bin/java java /usr/lib/jvm/java-7-oracle/jre/bin/java 100
# update-alternatives --quiet --install /usr/bin/java_vm java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm 100
# update-alternatives --quiet --install /usr/bin/javaws javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws 100
# update-alternatives --quiet --install /usr/bin/jcontrol jcontrol /usr/lib/jvm/java-7-oracle/jre/bin/jcontrol 100
# update-alternatives --quiet --install /usr/bin/keytool keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool 100
# update-alternatives --quiet --install /usr/bin/pack200 pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200 100
# update-alternatives --quiet --install /usr/bin/policytool policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool 100
# update-alternatives --quiet --install /usr/bin/rmid rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid 100
# update-alternatives --quiet --install /usr/bin/rmiregistry rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry 100
# update-alternatives --quiet --install /usr/bin/unpack200 unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200 100
# update-alternatives --quiet --install /usr/bin/orbd orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd 100
# update-alternatives --quiet --install /usr/bin/servertool servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool 100
# update-alternatives --quiet --install /usr/bin/tnameserv tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv 100
# update-alternatives --quiet --install /usr/bin/jexec jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec 100

Now you can use update-alternatives to select newly installed Java SDK.

# update-alternatives --config java              # Select java-1.7.0-oracle
# update-java-alternatives --set java-1.7.0-oracle
# exit
$

This worked for me, if there is a more elegant way (without using third-party PPAs) I'd be glad to hear about it. I still need to test Firefox if I can run Java in it.

5
  • 1
    Works great, except the final command issues an error (though everything else works, even in Firefox/Chrome). This seems to be from the default OpenJDK6 install with Oneiric."update-alternatives: error: no alternatives for -javaplugin.so." In the hidden .java.1.6.0.jinfo file there seems to be an alternative pointing to -javaplugin.so. Are we supposed to make a 3rd alternative point to libnpjp2.so with it perhaps?
    – Nicholi
    Oct 25, 2011 at 23:13
  • 2
    I decided to put the steps mentioned by BigWhale above in a simple shell script. The only manual step is to download the 64bit tar.gz from Oracle's site. Have a look at the instructions here.
    – julius
    May 29, 2012 at 20:46
  • 1
    This is the only solution that shows how to add the man pages!
    – DavidGamba
    Oct 14, 2013 at 5:55
  • @DavidG Alien Andrei's solution also works flawlessly
    – Anwar
    Dec 12, 2014 at 10:10
  • 1
    Also this solution is for 64bit Ubuntu. for 32bit, we should have i386 instead of amd64
    – Anwar
    Jan 1, 2015 at 11:16
25

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists here only for historical reasons.

An updated answer:

I suggest using one of the installers from the webupd8team ppa in this way:

  1. Enter these 2 commands in the Terminal to add this PPA and update your packages list:

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    
  2. Enter one (or more) of these commands to install the proprietary Java(s) you require:

    sudo apt-get install oracle-java6-installer
    sudo apt-get install oracle-java7-installer
    sudo apt-get install oracle-java8-installer
    sudo apt-get install oracle-java9-installer
    
  3. When the respective Java installer script is loaded and then it downloads and installs the proprietary Java packages, you can also enter the following command to check the result of the installation:

    java -version
    

You should then get a terminal output (for java8 stable version) like this:

java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

Further info: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

NB: These packages provide Oracle Java JDK, which includes Java JDK, JRE and the Java browser plugin. And the webupd8team/java PPA contains only these installers, which simply connect to Oracle Java download site and install the latest JDK.

4
  • 1
    Thanks for answer. Only this way made my Chrome JRE worked!
    – fth
    Aug 23, 2013 at 5:57
  • does it install just the jre or entire jdk, if entire jdk, then what's way to restrict installation only to jre ? Sep 12, 2013 at 18:16
  • does this type of installation provide me with automatic updates as they are released & wont adding this ppa add other kinds of softwares unknowingly to my server? Sep 12, 2013 at 18:17
  • 4
    This installs the JDK: "This package provides Oracle Java JDK 7 (which includes Java JDK, JRE and the Java browser plugin). However, you can't only install Oracle JRE - the PPA only provides the full Oracle JDK7 package." ref
    – kiri
    Nov 21, 2013 at 21:11
16

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of historical reasons.

I appreciate all the previous answers. I want to add this answer to simplify things which is done by www.webupd8.org to make installation in 2-5 minutes.

This installation includes:

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

That's all!! Now to check the Java version

java -version

The output will be like

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) Server VM (build 23.25-b01, mixed mode

There may come a new version, and then you can simply update it with this command:

sudo update-java-alternatives -s java-7-oracle

Setting up environment variables

sudo apt-get install oracle-java7-set-default

For more, check out Install Oracle Java 7 in Ubuntu via PPA Repository.

2
  • 3
    2-5 minute? it took 77 minutes
    – user204653
    Dec 20, 2013 at 12:51
  • 3
    Nice solution. This should be upvoted higher up. The installation time may take longer than 5 minutes depending on your internet speed (the download is ~70MB). As for setting the default Java machine, I prefer: sudo update-alternatives --config java.
    – landroni
    Oct 5, 2014 at 14:15
15

This solution will give you clean built packages just as they used to ship with Ubuntu before Oracle came around.

The answer

First the answer, then the explanation. Open a terminal and copy and paste the following, line by line.

wget https://raw.githubusercontent.com/ladios/oab-java6/master/oab-java.sh -O oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh

This will build the official sun-java6-* packages and make them available in the software-center. If you also want oracle-java7-* packages, run the script like this:

sudo ./oab-java.sh -7

Now you can install the packages with your preferred package manager.

The explanation

When Oracle changed the distribution license for Java, Linux distributions weren't allowed to update the official packages anymore. Github user rraptorr took the Debian script that was used to build the packages until then, and modified it to work with the updated downloads from Oracle. He now provides packging scripts for SUN Java6 and Oracle Java7.

The oab.java.sh script is just a wrapper that automatically downloads the current version, creates the packages and adds them to a local repository.

Further notes

Packages created and installed using this method, will not receive updates automatically - only when you rerun the script. You can circumvent this by creating a cronjob that runs this script on a regular basis. The savest way to do this is using anacron by putting the script in /etc/cron.daily.

wget https://raw.githubusercontent.com/ladios/oab-java6/master/oab-java.sh -O /root/oab-java.sh
chmod +x /root/oab-java.sh
ln -s /root/oab-java.sh /etc/cron.daily/oab-java

Now your official Java packages will always be up-to-date.

6
  • 1
    I've had so many issues with this script -_-
    – qodeninja
    Sep 25, 2012 at 5:04
  • @qodeninja, like what? I've never had an issue with this script. Executing the 3 line above will definately work on every Ubuntu machine, if it is not broken.
    – mniess
    Sep 26, 2012 at 16:28
  • I have a new linode instance of ubuntu 10.04 and I was trying to install jre 7 with this script. The script would hang for far too long because of missing dependencies. Then I had to stop the script and install the dependencies myself with apt-get. Even after I had everything installed the script still failed.
    – qodeninja
    Sep 26, 2012 at 18:20
  • The script really doesn't do anything special. Sounds like something is wrong with your box. I have been (and am) using this from 8.04 to 12.04 and never had problems. I just tried this on my 10.04 server which is pretty much vanilla, and it works as well. As it should, because this script doesn't do more than use the old debian build-scripts that packagers used to provide sun-java* for debian (and ubuntu).
    – mniess
    Sep 27, 2012 at 22:27
  • On Lubuntu 15.04 It starts fine, but after a while I get debian/rules:67: recipe for target 'get-orig-source' failed make: *** [get-orig-source] Error 22 make: Leaving directory '/var/local/oab/src' 11678's retcode: 2 failed
    – rubo77
    May 16, 2015 at 19:56
10

This worked for my development needs of being able to run/compile 1.6 or 1.7. Previously I was just running 1.6 from a Ubuntu apt package.

  1. Download 1.7 gzip.
  2. Extract to folder
  3. Update JAVA_HOME and PATH in bash file

    JAVA_HOME=/opt/java/jdk1.7.0_25
    export JAVA_HOME
    
    PATH=$JAVA_HOME/bin:$PATH
    export PATH
    
9

On AMD64 you need modify a little the command to create the symbolic link:

ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

only change the i386 to amd64.

3
  • Good shout! Wasn't working on my 12.04 64-bit until I read your answer. Thanks!
    – Scaine
    Jul 11, 2012 at 18:43
  • 2
    -1. This answer is completely out of context..
    – landroni
    Oct 5, 2014 at 13:47
  • 1
    It's not the answer of the question. Instead, it should be a comment
    – Anwar
    Jan 1, 2015 at 8:18
7

To make it available for all users :

sudo ln -s /usr/lib/jvm/jre1.7.0/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins/

for x86_64 :

sudo ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins/
1
  • 1
    Many thanks! This is what was missing for my java to work on firefox. Nov 6, 2012 at 13:42
7

Get the JDK from Oracle/Sun; download the Java JDK at:

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

Please download or move the downloaded file to your home directory, ~, for ease.

Note:

  • Don't worry about what JDK to download for JEE.

  • Please skip copying the Prompt " user@host:~$ ".

  • Hit enter after each command.

Run in a terminal..

user@host:~$ sudo mkdir -p /usr/lib/jvm/
user@host:~$ sudo mv jdk-7u4-linux-i586.tar.gz /usr/lib/jvm/
user@host:~$ cd /usr/lib/jvm/
user@host:~$ sudo tar zxvf jdk-7u4-linux-i586.tar.gz

Now enable Java (by running individually):

user@host:~$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_04/bin/java" 1
user@host:~$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_04/bin/javac" 1
user@host:~$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_04/bin/javaws" 1

Close all browsers.

Create a Mozilla plugins folder in your home directory:

user@host:~$ mkdir ~/.mozilla/plugins/

Create a symbolic link to your Mozilla plugins folder. For 64-bit systems, replace ‘i386’ with ‘amd64’:

user@host:~$ ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

Testing:

user@host:~$ java -version

Output:

java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)

Testing:

user@host:~$ javac -version

Output:

javac 1.7.0_04

Verify JRE at http://java.com/en/download/installed.jsp.

5

I propose one way to make easier the installation of Oracle's Java 7.

Since Ubuntu does not provides the Oracle's Java 7 packages, I'm providing a collection of Ubuntu packages on my own package repository.

The packages are fully integrated in the Ubuntu way to support Java. You will be able to select the Oracle's Java 7 alternative with the standard tools: update-alternative or update-java-alternative.

The main page of my contribution is: http://www.arakhne.org/jdk/index.html

To obtain the packages, you only need to add my package repository into your system configuration. The process is explained in http://www.arakhne.org/ubuntu.html

Stéphane.

2
  • 10
    ... just friendly advice - check oracle's redistribution license ... you dont want oracle's lawyers chasing you!
    – fossfreedom
    May 9, 2012 at 11:44
  • 1
    Please do not post duplicate answers on different questions. It just creates more work for the moderators. If the questions are so similar that the same answer works on each, then the later of the two is likely a duplicate and should be flagged as such.
    – RolandiXor
    Nov 22, 2013 at 4:28
4

The easiest way is just downloading java 7 with Netbeans here - http://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-432126.html

4

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of historical reasons.

For those who live in Syria, Cuba, Libya, Korea or any country where Oracle is banning its services, this is a working way to install Oracle JDK 8.

  1. Using a PROXY, go to this link and accept the terms then download the tar.gz suitable to your system (32 or 64 bit).
  2. Move that tarball to the Downloads directory in your home folder.
  3. run this script as sudo:


if [[ $UID != 0 ]]; then
  echo "This script neeeds to be run with sudo, like this:"
  echo -e "\n  sudo $0 $*\n"
  exit 1
fi
apt-get install python-software-properties
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer
if [ ! -f $HOME/Downloads/jdk-8u5-linux-*.tar.gz ]; then
  echo "The JDK tar.gz file was not found in $HOME/Downloads. please download it, put it in $HOME/Downloads and run again."
  exit 1
fi
cp ~/Downloads/jdk-8u5-linux-*.tar.gz /var/cache/oracle-jdk8-installer/
apt-get install oracle-java8-installer
apt-get install oracle-java8-set-default
java -version
3

For me it's a little bit different. For Ubuntu 12.04 LTS Precise (Desktop):

  1. Download jre-*.tar.gz

  2. tar -zxvf jre-*.tar.gz

  3. mkdir /usr/lib/jvm/

  4. mv jre* /usr/lib/jvm/

  5. ln -s /usr/lib/jvm/jre*/bin/java /usr/bin/

That's all.

To make sure it's correct:

java -version

If you want to add plug in for Firefox or Chrome:

  1. mkdir ~/.mozilla/plugins

  2. ln -s /usr/lib/jvm/jre*/lib/i386/libnpjp2.so ~/.mozilla/plugins/

Special Note: If you have a fresh 64 bit install, you may experience the following error when running java -version

-bash: ./java: No such file or directory

This is caused by a dependency on the libc6-i386 package which is not included by default in 64 bit Ubuntu Desktop 12.04 LTS. To install this package, run: sudo apt-get install libc6-i386

1
  • 1
    The instructions you provide to add a plugin for Firefox or Chrome do not affect Chrome at all. Chrome does not use the contents of the .mozilla folder. Jul 3, 2012 at 0:46
3

Here's a bash script that could help in setting up the java alternatives:

#!/bin/bash

BIN_HOME="/usr/bin"
JVM_BIN_HOME="/usr/lib/jvm/jdk1.7.0_21/bin"

UPDATE_CMD="update-alternatives"
UPDATE_OPT="--install"
UPDATE_DEFAULT_PRIORITY=10

echo "Installing alternatives for Oracle JDK."
#echo "JAVA_BIN_HOME=$JAVA_BIN_HOME"
#echo "BIN_HOM=$BIN_HOME"
echo "All cmds in \"$JVM_BIN_HOME\" will be installed in \"$BIN_HOME\" with \"$UPDATE_CMD\""
echo

# 
# Calls update-alternatives.
# Param 1 is the java cmd name and optionally param 2 is the priority
# See 'man update-alternatives' for more information.
# 
function update_alt() {
    if [ -z "$2" -o "${2}xxx" = "xxx" ]; then
    echo "using default priority: $UPDATE_DEFAULT_PRIORITY"
    PRIORITY=$UPDATE_DEFAULT_PRIORITY
    else
    PRIORITY=$2
    fi

    EXEC="$UPDATE_CMD $UPDATE_OPT $BIN_HOME/$1 $1 $JVM_BIN_HOME/$1 $PRIORITY"
    echo $EXEC
    $EXEC
    return 0
}

for bin in $JVM_BIN_HOME/*
do
    if [ -x $bin ]; then
    cmd=$(basename $bin)

    if [ -x $BIN_HOME/$cmd ]; then
        echo "notice: alternative already installed, \"$cmd\""
        continue # Skip installation of alternative.
    fi

    echo "install alternative: $cmd"
    update_alt $cmd
    if [ ! -x $BIN_HOME/$cmd ]; then
        echo "error: failed to install alternative, \"$cmd\""
        exit 1
    fi
    fi
done

exit 0
3

Straightforward Solution

Rather than downloading the .tar.gz package I recommend you download the .rpm package. Then run:

sudo apt-get install alien dpkg-dev debhelper build-essential
sudo alien --scripts jdk-7u-linux-.rpm 

where I believe the current <build> is 21 and the <version> depends on your system architecture.

The first will install alien, a application for converting .rpm to .deb. The second command then runs alien on jdk package. This should run for a minute or two and produce a file labelled:

jdk-7u<build>-linux-<version>.deb

This package may then be installed by running:

sudo dpkg -i jdk-7u<build>-linux-<version>.deb

This is how I successfully installed it on my machine.

1
  • 1
    Would this update the alternatives? probably only copy the files.
    – DavidGamba
    Oct 23, 2013 at 4:25
3

I think that the best method has been already posted but I had some problem with this : namely I remove java 'manually' from update-alternatives and then I have tried to do this

update-alternatives --install "/usr/bin/java/" "java" "/usr/lib/jvm/jre1.7.0_05/bin/java" 1

but I kept on getting this error

update-alternatives: using /usr/lib/jvm/jre1.7.0_05/bin/java to provide /usr/bin/java/ (java) in auto mode. update-alternatives: error: unable to make /usr/bin/java/.dpkg-tmp a symlink to /etc/alternatives/java: No such file or directory

But fortunately I have encountered a great tutorial on this site : http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html and it worked just fine :)

1
  • /usr/bin/java is not a folder, that's why the error
    – Anwar
    Apr 13, 2017 at 5:04
3

For installing the 32-bit variant of Java on 64-bit Ubuntu:

Open up a terminal window ( Ctrl + Alt + T is the quickest method if you're not aware) and type in the following to install:

sudo add-apt-repository "deb http://download.tuxfamily.org/arakhne/ubuntu precise-arakhne universe"

wget http://download.tuxfamily.org//arakhne/public.key -O - | sudo apt-key add -
apt-get install ia32-oracle-java7-jre
2

The best method that I can deliver if you want to install Java 6 under Ubuntu 12.04 LTS (Precise Pangolin) is:

sudo apt-get purge sun-java

You need to do that if you want the Mozilla plugin to work without conflict with Java 7 for instance.

mkdir ~/src

cd ~/src
git clone https://github.com/flexiondotorg/oab-java6.git
cd ~/src/oab-java6
sudo ./oab-java.sh

Then when it's finished, install Java:

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

You can follow the installation process with:

tail -f ~/src/oab-java6/oab-java.sh.log

Explanation: the same as in an answer to How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE?.

Ref: Installing Java6 JDK on Ubuntu 12.04

2

To me the Debian way (sic) would be to create your own package.

You install java-package

sudo apt-get install java-package

You download the Oracle tar.gz archive.

You create your deb package

fakeroot make-jpkg jdk-7u79-linux-x64.tar.gz

An you install it

sudo dpkg -i oracle-java7-jdk_7u79_amd64.deb
2

Download your desired .tar.gz version of JDK for your Ubuntu system from http://oracle.com, for example jdk-8u102-linux-x64.tar.gz.

Extract it to anywhere you want in /home directory, for example /home/dante/Programs/Java. Now we have a folder with the name like jdk1.8.0_102 inside /home/dante/Programs/Java.

Add these two lines to your /home/dante/.profile file

export JAVA_HOME=/home/dante/Programs/Java/jdk1.8.0_102
export PATH=$JAVA_HOME/bin:$PATH

Restart your system and after reboot you should see your Java version by running java -version in terminal.

2

I don't know why people have given so much big answers but adding jdk/bin to PATH works just fine:-

Add your jdk/bin to PATH as told here in my case this is how my /etc/environment looks:-

   $ cat /etc/environment     
   PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/jdk-9.0.1/bin"    
   JAVA_HOME="/opt/jdk-9.0.1/"
1

To install Sun Java 6 on Precise through Trusty, you can use the Preserved Removed Primary/Partner Archive packages PPA.

sudo add-apt-repository ppa:maxb/preserved
sudo apt-get update
sudo apt-get install sun-java6-jre
sudo update-alternatives --config java

And then select the desired Java version. You can check what you're now running by:

geek@liv-inspiron:/tmp$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
1

Installing Oracle Java (JDK/JRE):

You can automate the task of installing/uninstalling Oracle Java (JDK/JRE) from a downloaded (tar.gz) source with this script: oraji.

Steps:

  1. Download the tar.gz source of your desired jdk/jre version.
  2. run sudo oraji /path/to/the/jdk_or_jre/archive

Uninstall:

run sudo oraji -u and confirm the jdk/jre version to be uninstalled.

0
1

You can download the latest Oracle JDK 8, then you open a terminal with 'Ctrl + Alt + t' and enter the following commands:

cd /usr/lib/jvm

If the /usr/lib/jvm folder does not exist, enter this command will create the directory sudo mkdir /usr/lib/jvm

Then extract the jdk-{version}.tar.gz file in that directory using this command.

sudo tar -xvzf ~/Downloads/jdk-{version}.tar.gz

The the following command to open the environment variables file.

sudo vim /etc/environment

In the opened file, add the following bin folders to the existing PATH variable.

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-{version}/bin:/usr/lib/jvm/jdk-{version}/db/bin:/usr/lib/jvm/jdk-{version}/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk-{version}"
J2REDIR="/usr/lib/jvm/jdk-{version}/jre"
JAVA_HOME="/usr/lib/jvm/jdk-{version}"
DERBY_HOME="/usr/lib/jvm/jdk-{version}/db"

Save the changes and close the vim.

Then enter the following commands to inform the system about the Java's location.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-{version}/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-{version}/bin/javac" 0
sudo update-alternatives --set java /usr/lib/jvm/jdk-{version}/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/jdk-{version}/bin/javac

To verify the setup enter the following commands and make sure that they print the location of java and javac as you have provided in the previous step.

update-alternatives --list java
update-alternatives --list javac

Now restart the terminal again and enter following commands.

java -version
javac -version

If you get the installed Java version as the output, you have successfully installed the Oracle JDK in your system.

0

OS: Ubuntu 18.04 LTS

I am surprised no one has mentioned conda . Link:
https://docs.conda.io/en/latest/miniconda.html

I installed java in one of my conda environments and used the java command without problems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .