Oracle Java is removed from the official software repositories of Ubuntu as it is closed source.
Ubuntu 12.04 is shipped with Open Source OpenJDK6 and the IcedTea plugin, which is more adequate for many developers. OpenJDK6 is available in the Ubuntu repositories and receives security updates.
However, still some developers require Oracle Java for development. Lets begin installing Oracle Java in Ubuntu 12.04.
Go to Java download page from the below link and choose the necessary version of Java.
Download Java SDK
Choose the necessary version of Java SDK and click on the “Accept the License Agreement”.
On accepting the license Agreement, the download link will be ready. Click on the jdk-**-linux-i586.bin, this will get downloaded in your ~/Downloads folder.
Now open terminal.
To open the terminal from Dash Home, click on the ubuntu logo and type terminal. Select the terminal
(You can also open terminal, by pressing “CTRL + ALT + T”)
Create a folder named java in usr folder through terminal.
sudo mkdir /usr/java
Navigate to /usr/java folder.
Copy the downloaded bin file from the Download folder.
sudo cp ~/Download/jdk*.bin .
The bin requires execute permission to install the java. So lets provide execute permission to it.
sudo chmod a+x jdk*.bin
To know more about chmod, click here.
Now we are ready for installing the Java SDK. Install java sdk by entering the following command
We are done with Oracle Java SDK installation.
The last important step, we need to create the link for java in /usr/bin.
sudo ln -s /usr/java/jre*/bin/java /usr/bin/java
If you get an error saying that
ln: failed to create symbolic link '/usr/bin/java':File exists
then remove existing link by
sudo rm /usr/bin/java
and try creating the link again.
Once you are done, now check the version of Java installed by typing