How to install java in linux

How to install java in linux

Procedure 1

Download the Java software from the Sun site. See to it that you download the version for Linux platform and not the Windows one. Most probably you would get the software as atarball (.tgz). If you get it as an Windows Executable (.exe) file then you got the wrong one.
You can install Java in any directory. But if you want all the users to access Java then it is better to install it under the /usr/local directory.
I shall explain a simple way where you would extract the files from the tarball and then copy them to the /usr/local directory. Type the following command to extract the files from the original tarball

gunzip -dc jdk.x.x.x.tgz | tar xf –

This would extract all the files into a directory named jdk.x.x.x in the same parent directory that had the original tarball.
Copy this entire directory into the /usr/local directory. So you would finally have a structure as /usr/local/jdk1.2.2
Check that the jdkx.x.x directory has a /bin , /lib and a few other folders inside it.
Finally you got to add these executables (namely java, javac) to your path. Else you would have to give the absolute path every time you want to use these executables.
Edit the /HOME/.bash_profile file and make suitable changes to the path variable in it


Once you save the file then execute the file by typing the following

. $HOME/.bash_profile

Once this is over you can use your normal editor (Emacs is what I use) to write your Java programs and then simply type the following to compile and then run your program

# To compile your program
# To execute the program
java Myprogram

Procedure 2

Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s. Java applications are compiled to bytecode, which at runtime is either interpreted or compiled to native machine code for execution.

The language itself derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. JavaScript, a scripting language, shares a similar name and has similar syntax, but is not directly related to Java.
Currently Ubuntu has the following Java packages
sun-java6-bin — Contains the binaries
sun-java6-demo — Contains demos and examples
sun-java6-doc — Contains the documentation
sun-java6-fonts — Contains the Lucida TrueType fonts from the JRE
sun-java6-jdk — Contains the metapackage for the JDK
sun-java6-jre — Contains the metapackage for the JRE
sun-java6-plugin — Contains the plug-in for Mozilla-based browsers
sun-java6-source — Contains source files for the JDK
Installing the Java Runtime Environment
First you need to check multiverse repository enabled or not after that open a terminal window. Since you are going to be installing the JRE and the web browser plug-in, you’ll be using the following command from a terminal
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
Once it downloads the packages and begins the installation, you’ll get a screen that contains the Sun Operating System Distributor License for Java and hit Enter to continue. You’ll see a dialog that asks you if you agree with the DLJ license terms. Select Yes, and hit Enter; the JRE will finish installing.
Testing Java Runtime Environment
You’ll want to confirm that your system is configured properly for Sun’s JRE. This is a two-step process.
First, check that the JRE is properly installed by running the following command from a terminal.
java -version
You should get similar output
java version “1.6.0″
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
Testing Java Plugin for Firefox
open Firefox and typing about:plugins in the address bar and check for java plugin

This entry was posted in Java Programming and tagged . Bookmark the permalink.