Tuesday, August 3, 2010

How to install Java in Ubuntu /Linux

There are two methods to install JRE/JDK in Ubuntu
(1) Online:

#sudo apt-get install sun-java6-jre (for users)
#sudo apt-get install sun-java6-jdk (for developers)
#sudo apt-get install sun-java6-plugins (java plugins)
#sudo apt-get install sun-java6-fonts (java fonts)
Or you can run all commands together
#sudo apt-get install sun-java6-jre sun-java6-plugins sun-java6-jdk

(It will download JRE/JDK from Sun site and install in your system)

To check java version
#java -version

Or type in FireFox URL
about:plugins
It will display installed java plugins.

(2) Offline:

(a) Non -RPM package (bin)

(i) Download the JDK from Sun
(ii) Click on the "Download" link in the JDK 6 section.
(iii) Accept the license and continue.
(iv) Under the "Linux Platform", select "self-extracting file".
(v) Download this .bin file and save it to your GNU/Linux machine.
(vi) Once it has been downloaded, switch to the directory where you saved the file. You do not need to be a root and only must have the write access to the folder where you wish to install java. If your administrator is not supportive, you may need to place java into your home folder or even better on some shared network location.
(vii) Type sh name_of_the_downloaded_file, for instance sh jdk-6u2-linux-i586.bin. There is no need to make this file executable.
(viii) The license agreement should start to appear on the screen. Scroll to the end of it with 'Enter' and type yes.
(ix) This installer will create its installation in the same folder, where the downloaded file was placed and from where you have started the installation script. But the installed java jre is rather independent and can be easily moved into another place just by copying all its files.
(x) You can install multiple different jre's this way: they coexist together and can be used if some software requires the older version to run.
(xi) The java executable you need to launch is located in a subfolder, called 'bin'. This way of installation will not configure a default 'java' command for you: you must do this manually or always include the full path in your startup script.

(b) RPM package

(i) Download the JDK from Sun
(ii) Click on the "Download" link in the JDK 6 section.
(iii) Accept the license and continue.
(iv) Under the "Linux Platform", select "RPM in the self-extracting file".
(v) Download this .bin file and save it to your GNU/Linux machine.
(vi) Once it has been downloaded, login as root and switch to the directory where you saved the file.
(vii) Execute './filename', where filename is the name of the file that you downloaded. The filename might be very similar to jdk-6-linux-i586-rpm.bin depending on what the latest version is. You may have to make the file executable by executing the 'chmod +x filename.bin' command.
(viii) You will get a license, press space bar a bunch of times until you are prompted to enter yes or no. Type in yes and hit enter.
(ix) This will place a .rpm file in the same directory as your .bin file with the same name (minus the .bin part).(x) Install the rpm file by executing 'rpm -i filename.rpm', where filename is the name of your .rpm file. (Such as jdk-6-linux-i586.rpm).
(xi) Now, if you want to be able to execute this version of Java interpreter or compiler from any directory on your GNU/Linux system you will have to create a few symbolic links:

     ln -s /usr/java/jdk1.6.0/bin/java /usr/bin/java
     ln -s /usr/java/jdk1.6.0/bin/javac /usr/bin/javac

(xii) You are done :)

No comments:

Post a Comment