Tips For Linux

>> Installing Java under Linux

This article explains how to install Java on your Linux machine so that you can write, compile and execute Java programs on your machine. I have had extensive programming experience in Java (under Windows), so when I shifted over to Linux , the first thing I got running under Linux was Java 1.2


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 a tarball (.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
javac Myprogram.java
# To execute the program
java Myprogram

Now you can do all your Java coding under Linux. Happy Coding !!

Tips For Linux © All Copyrights Reserved