Library Technology – Reviews, Tips, Giveaways, Freeware

Linux tips: Installing Java in Linux

Posted In Linux - By Techtiplib on Sunday, June 10th, 2012 With No Comments »

This posting 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.

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 a tarball (.tgz). If you get it as an Windows Executable (.exe) file then you got the wrong one.

2. 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.

3. 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 –

4. This would extract all the files into a directory named jdk.x.x.x in the same parent directory that had the original tarball.

5. Copy this entire directory into the /usr/local directory. So you would finally have a structure as /usr/local/jdk1.2.2

6. Check that the jdkx.x.x directory has a /bin , /lib and a few other folders inside it.

7. 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.

8. Edit the /HOME/.bash_profile file and make suitable changes to the path variable in it

PATH=/usr/local/jdkx.x.x./bin/:$PATH

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

. $HOME/.bash_profile

10. 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 !!

Source: codecoffee.com

More contents in: , ,

About -

Hey, this blog belongs to me! I am the founder of TechTipLib and managing editor right now. And I love to hear what do you think about this article, leave comment below! Thank you so much…