Sunday, September 27, 2009

install Java on Linux

Hi all, Today, I'm going to talk about some very basic things, actually this is a summary of what i did in yesterday workshop.

How to install Java 

since java is a platform independent language and runs on a virtual machine we need to install something called SDK (or JDK) in other words Software Development Kit.
there are few ways to install Java 
  • if you don't have an Internet connection but can access internet from some other place here is the way to install Java :
first download the SDK you will get a file with a .bin extension
now go to Applications --> Accessories --> Terminal (in Ubuntu) change the directory place where you downloaded the bin file.

e.g
if your file is in a folder called download in your home directory type :

cd ~/Download

~ is a simple way of typing the path to home directory.
then type
./name of the file.bin
remember this will install Java in the present working directory (type pwd in the terminal if you want to see the directory)

if you have followed the previous steps correctly you can see a license agreement scroll down until you find the end of the license then type y (or yes) and press enter



after few moments Java will be installed in your system.

How to set the environment variable 

after installing Java if you try to compile a java code what will happen ?
you can't do any compilations since we haven't set the PATH variable (but if you install java directly from repositories you don't need to do that i will come to that point later)

first type

gedit ~/.bashrc

* in linux files that starts with a dot(.) are the hidden files
then add this line to that file and save

export PATH=$PATH:/path to bin


 

(click on the image to enlarge)

now exit from the terminal and open it again. now you can compile and run your java programmes on linux.

  • if you have an Internet connection
then the life is much easier for you you just need to type :

sudo apt-get install sun-java6-jdk

and press enter then you will be prompted to enter your password. after installing java in this way you don't need to edit the .bashrc file.


enjoy this week with Java and Linux
cheers !
Kesh,

No comments:

Post a Comment