Thursday, May 18, 2006

Installing Java 5 JDK and Tomcat on Ubuntu (using VMWare)

This document will walk you through installing Apache Tomcat on Ubuntu Linux using VMware for virtualization. Most of the steps apply even if you're not using VMware.

  1. Download and install VMWare on your server
  2. Download and install VMWare client on your workstation (if it is different than your server)
  3. Option 1: Prepackaged Ubuntu VM (Please note, this will NOT work on a headless server)
    1. Download Ubuntu VM from www.vmware.com
    2. Open Ubuntu VM (user/pass is ubuntu/ubuntu) in VMWare client
  4. Option 2: New fresh install of Ubuntu (you have to do this if you have a headless server)
    1. Download Ubuntu ISO from www.ubuntu.com
    2. Create new virtual machine in vmware, choose Linux -> Ubuntu
    3. Mount the cd drive for the virtual machine to your downloaded iso in the virtual machine settings
    4. Start virtual machine, this will ask if you want to install, so perform the full install (this is just a regular Ubuntu install)
  5. Now you should be in Ubuntu linux
  6. modify /etc/apt/sources.list (ex: run: sudo nano -w /etc/apt/sources.list)
    - Change the first section lines deb http://archive.ubuntu.com/ubuntu breezy main restricted
    to deb http://archive.ubuntu.com/ubuntu breezy main restricted universe multiverse
    You can also add universe multiverse to deb-src and do the same to the breezy-update lines too.
    (breezy will be dapper in 6.X versions)
  7. run: sudo apt-get update
  8. Install JDK
    1. Option 1:
      1. run: sudo apt-get install sun-java5-jdk
    2. Option 2: (if option 1 doesn't work)
      1. download jdk 1.5 from sun, the Self extracting linux version, .bin extension (NOT rpm)
      2. run: sudo apt-get java-package
      3. run: fakeroot jdk***.bin
      4. run: sudo update-alternatives --config java
        - select the j2sdk1.5-sun option
      5. run: java -version
        - just to make sure it's the new version
  9. add:
    export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.06
    if you used Option 1 for installing JDK above or:
    export JAVA_HOME=/usr/lib/j2sdk1.5-sun
    if option 2 was used
    to /home/ubuntu/.bashrc
  10. Open a new console window to continue with the rest of the steps
  11. Download tomcat 5.5 from tomcat.apache.org
  12. extract tomcat (to a directory under your HOME directory is a good idea - /home/ubuntu/java/apache-tomcatXXX)
  13. go to tomcat directory/bin
  14. run: ./startup.sh
  15. surf to http://yournewserversip:8080/
    1. You should see the Tomcat welcome page
If you want to run Tomcat as a service: http://tomcat.apache.org/tomcat-5.5-doc/setup.html

Other tips:
- If you want to use 7-zip which is nice for all compression/decompression tasks, run: "sudo apt-get install p7zip", then to extract anything, you just run "7za x myfile" (.zip or .tar or .tar.gz or .7z, etc)
- If you want an ssh server (sshd) on your new ubuntu box, run: "sudo apt-get install openssh-server". Apparently Ubuntu does not come with an ssh server installed out of the box.
- if you use nano, while you're editing .bashrc above, it's a good idea to add an alias for nano with the -w option like: alias nano='nano -w'
- VMware kicks a**, so be sure to try it (note: I have no affiliation with VMware, I just like good products)

If you have any issues with the steps above or want to add anything, please post your comment below.

Good night and good luck...