Wednesday, November 5, 2008

How to install Java and Tomcat6 for Ubuntu 8.04

For Ubuntu 8.04, hope this little contribution can help you installing Java and setting your tomcat server.

Step 1. Download the latest Tomcat to your desktop: http://tomcat.apache.org/download-60.cgi , then run

sudo tar zxvf apache-tomcat-6.0.10.tar.gz (or name of the latest downloaded tomcat .gz file).
sudo cp -R apache-tomcat-6.0.10 /usr/share/tomcat6 (or name of the unziped tomcat file).

Step 2. Setting JAVA environment
Download the latest J2SE SDK from http://java.sun.com/javase/downloads/index.jsp, and run
sudo chmod +x *.bin
sudo sh ./jdk*.bin

Executing the .bin file creates a folder on your desktop named jdk1.6.0_01(or latest java version folder).
Rename that folder to Java6u1. Now move that folder to /usr/lib

sudo mv Java6u1 /usr/lib
sudo update-alternatives --install /usr/bin/java java /usr/lib/Java6u1/bin/java 300
sudo update-alternatives --config java

1 /usr/lib/Java6u1/bin/java
2 /usr/bin/gij-wrapper-4.1
3 /usr/lib/jvm/java-gcj/jre/bin/java

you will get a list that looks like above. now select that we recently copied one. here option 1.

Step 3. Setting the following environment /etc/environment
sudo gedit /etc/environment,
then insert and save two lines:
CLASSPATH=.:/usr/lib/Java6u1/bin (or latest path based on your naming )
JAVA_HOME=/usr/lib/Java6u1 (or latest path based on your naming)

Step 4: Tomcat needs to set JAVA_HOME or JRE_HOME to execute.
Open the follow document and edit the lines:

sudo gedit ~/.bashrc
then place the following lines in:

export JAVA_HOME=/usr/lib/Java6u1 ( or your latest path based on your naming)
export PATH=$PATH:$JAVA_HOME/bin

Step 5: Start and stop tomcat
Now start your tomcat:
sudo /usr/share/tomcat6/bin/./startup.sh
Type "http://localhost:8080" in your browser. If you see the tomcat welcome page, your tomcat is running smoothly.
If you are installing below 5.5 version, please try 8180.

Stopping tomcat:
sudo /usr/share/tomcat6/bin/./shutdown.sh

Step 6: Tomcat administrator setting
Edit this document:
sudo gedit /usr/share/tomcat6/conf/tomcat-users.xml
before insert this line:

Save and restart your tomcat. You can login to your tomcat admin by using your new set id and password now.