Friday, August 08, 2008

How to Install Sun JDK, Eclipse, and Apache Tomcat in Ubuntu.

Due to my previous post and my next posts, I will tell you about configuration of my Ubuntu to develop software with Java. This post will cover Sun JDK as Java development kit, Apache Tomcat as application server and Eclipse as IDE.

--Install Java and setting JAVA_HOME environment variable and path--
Firstly, download file installation for Sun JDK. There are 2 kind binary files of Sun JDK Installation in Ubuntu. They are file with extension .deb and file with extension .bin. For example: sun-j2sdk1.5_1.5.0_i386.deb and jdk-1_5_0_01-linux-i586.bin. File with extension .deb is easy to install. Ubuntu is a variant of Debian, so file with extension .deb is easy known by Ubuntu. Just click twice on the file and ubuntu will automatically install JDK in /usr/lib/... By this way, try to run java -version with terminal.


In another side, file with extension .bin must be extracted into a specific folder. I prefer to place other file installation in /opt folder. In terminal, run this command:

~$ sudo mv /home/ndung/jdk-1_5_0_01-linux-i586.bin /opt
~$ sudo ./opt/jdk-1_5_0_01-linux-i586.bin


You can't run java or javac or java -version in terminal by this way directly. You must set path and environment variable in ubuntu. In terminal, run this command:

~$ sudo gedit /etc/bash.bashrc

Add these lines at below of that file:
export JAVA_HOME=/opt/j2sdk1.5-sun/
export PATH=$PATH:$JAVA_HOME/bin


Note: Although after installation by file with extension.deb, Ubuntu by terminal can run java -version directly, but the other program like Apache Tomcat, Eclipse, etc can't know directly where the path installation of Java. So you still need to set JAVA_HOME environment variable in Ubuntu just like above. In /etc/bash.bashrc file, add these lines:
export JAVA_HOME=/usr/lib/j2sdk1.5-sun/
export PATH=$PATH:$JAVA_HOME/bin


Now, test if path and environment variable are set correctly. In terminal, run this command:


--Install Apache Tomcat and setting CATALINA_HOME environment variable and path--

To install Apache Tomcat, just extract file installation (.tar, .tar.gz, .tar.bz2, .zip) into a specific folder. Example extract apache-tomcat-5.5.26.zip to /home/ndung/apache-tomcat-5.5.26 and then move it into /opt folder. Just like JAVA_HOME you must set a variable path of CATALINA_HOME. Add this line into /etc/bash.bashrc file:
export CATALINA_HOME=/opt/apache-tomcat-5.5.26/

--Install and Run Eclipse--
To install Eclipse, just extract file installation (.tar, .tar.gz, .tar.bz2, .zip) into a specific folder. Example extract eclipse-wtp-spring-subclipse.tar.bz2 to /home/ndung/eclipse and move to /opt folder. To run Eclispe just type this command in terminal:

~$ ./opt/eclipse/eclipse

To summarize my explanation above you can just create a simple launcher to run eclipse. Create file eclipse.sh in desktop. Fill that file with these lines and run it.

193 comments: