Thread: Installing Java
View Single Post
  #1 (permalink)  
Old January 13th, 2003
b4k4^ni b4k4^ni is offline
Disciple
 
Join Date: January 13th, 2003
Posts: 10
b4k4^ni is flying high
Thumbs up Installing Java

Installing Java on Linux seems to be a bit of a problem for newbies. Here are a few pointers that hopefully will make the installation a sucess.

Before you do anything, read this whole post and make sure you understand it.

First of all make sure you have a recent version of Linux as recomended by Sun.

Read the installation guide and don't skip steps even if they seem useless.

http://java.sun.com/j2se/1.4.1/jre/install-linux.html

Download the latest version of Java from Sun. You have two choices rpm and bin either one works as long as you follow the exact directions in the installation guide. Here is the java download page:

http://java.sun.com/j2se/1.4.1/download.html

There are a couple of gotchas here. The bin installation is not too clear on the root access. For that reason alone newbies should use the rpm installation.

When you do the rpm installation you first get a file with extension rpm.bin. This is a self extracting file that displays a license ageement and it prompts you to agree (type yes to the prompt) or not (type no). Before you self extract this file you must give it execute permission (chmod) as indicated in the first command of step 2 of the the installation guide. If you you fail to do so, you will not be able to execute the script. Do not attempt any shortcuts here or you may run into problems.

Yes, the current directory ( ./ ) in front of a command is important in Linux so you do need it in the second command of step 2. Unlike WIndows, the current directory in Linux is not in the PATH so executables will not be found if ./ is not specified.

After this step a file with extension rpm is created (if you ageed to the license).

Step 3 indicates to loggin as root. You do this with the "su" command.

Step 5 is done with the command "exit "


I just can't say it enough: Follow the exact instructions in the guide.

After you have succesfully installed Java, you need to make it accesible by modiying the PATH variable to include the java directory in the path. There a several way to do this. I prefer to make it a system wide change so I modify /etc/profile to have a line like this

PATH=<javadirectory>:$PATH

where <javadirectory> is where java executable got installed. The directory will be different according to the version you installed. To find out do this command:

find /usr/ -name "*j2*"

The find command will help you determine the directory that containts the Java installation. What you need is the subdirectory that contains the java executable. This subdirectory is "bin".

Example:

You found out that Java is in

/usr/java/j2re-1.4.0_02

The java executable is in directory

/usr/java/j2re-1.4.0_02/bin

Thus you should change your profile to have this line:

PATH=/usr/java/j2re-1.4.0_02/bin:$PATH

Some Java applications look for a variable called JAVA_HOME. You might as well set this variable in the profile and combine it with the PATH change.

Here is a way to setting up both the PATH and JAVA_HOME in our example where we assumed Java in /usr/java/j2re-1.4.0_02:

Add these lines to the profile:

JAVA_HOME=/usr/java/j2re-1.4.0_02
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME


IMPORTANT
Before you mess around editing /etc/profile make a copy of it. This way you could restore from the copy if necessary.

To make a backup copy do

cp /etc/profile /etc/profile.save


Windows users note that the different paths in the $PATH variable are separated by a colon ( : ) unlike Windows. Also environment variable in Linux are referenced with a $ sign.

Finally make sure you do your PATH and JAVA_HOME before the corresponding "export" commands in /etc/profile

Once you do this change you must login as a user to see if the change and do

echo $PATH
echo $JAVA_HOME

to verify that you have the right PATH and JAVA_HOME.

If you do you will be able to do

which java

and get the directory that has java. If you get an error review your settings and try it again.

Finally this command will tell you for sure if java is installed:

java -version

This should display the version of your java if not then review the steps and fix the problem.


Good luck.

Last edited by b4k4^ni; June 7th, 2003 at 04:45 AM.
Reply With Quote