Installing Sun Java on Older Versions of Ubuntu (9.10 and below)
I had the same problem once about three years ago with Ubuntu 8.04 I think. There was a weird problem when using openjre and the problem was solved by using the sun jre version. Here are the steps in the terminal which apply to versions below 10.04, since starting from 10.04 sun java has been dropped and replaced by openjre:
sudo apt-get remove openjdk-6-jre default-jre default-jre-headless
sudo apt-get install sun-java6-jre sun-java6-bin sun-java6-plugin sun-java6-fonts
(Everything Sun java related. Just to make sure)
After that, if you removed openjdk then you would only have sun java. If you did not remove it then you have both of them. To change from one to another do this:
sudo update-java-alternatives -l
- This will show you the list of java engines you can use.
The name of the java alternative is the one in the left so for example openjdk would appear like this:
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
And you would set the system to openjdk like this:
sudo update-java-alternatives -s java-6-openjdk
If you would want to use Sun then you would do this (After installation of the sun packages):
sudo update-java-alternatives -s java-6-sun
If you want to use the java 7 version, simply change the number 6 mentioned above for 7. For example if I wanted to install the openjre version 7 I would:
sudo apt-get install openjdk-7-jre default-jre default-jre-headless
Installing Sun Java on Newer versions of Ubuntu (10.04 an above)
Open the terminal and type the following:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install oracle-java7-installer
That should install the Sun Java version on your system. To change to it simply do the following in case you have other java alternatives:
sudo update-java-alternatives -s java-7-oracle
If you want the installation to be automatic type the following:
sudo echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
after that simply do the following to set the default environment variables:
sudo apt-get install oracle-java7-set-default
Note that the PPA includes versions 6, 7 and 8. So you can install any of them by simply changing the number in the installation line, for example:
sudo apt-get install oracle-java8-installer
Would install Java 8. After installing the Java version you wish to use and setting the version to the default with the update-java-alternatives
command, you can check which version you are using by typing the following:
java -version
It will show you the default version you are using at that moment.
I would like to also mention that OpenJRE/JDK has come a long way from 2 or 3 years ago when it had many issues that were solved by changing to Sun Java.
It turns out I needed to explicitly add support for 32-bit architecture to the system.
openjdk-7-jre:i386
installed successfully after I did this:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install openjdk-7-jre:i386
NOTE: ia32-libs
and any other necessary prerequisites are automatically selected and installed when you install openjdk-7-jre:i386
. There's no need to install ia32-libs
manually, and it's best to install the automatically selected libraries to ensure you definitely get the right version etc.
Best Answer
UPDATE : ALTHOUGH THIS IS THE MOST VOTED ANSWER ITS PROBABLY NOT THE ONE YOU WANT TO USE IN 2018 DUE TO LACK OF SECURITY UPDATES BY THIS PPA.
I found the following instructions which worked for me :
This defines the “PPA for OpenJDK uploads (restricted)” as an additional package repositiory, updates your information, and installs the package with its dependencies (from that repository).