How to install Tomcat

Step-by-step guide

  1. Download tomcat from http://tomcat.apache.org/download-70.cgi - if you do this from a browser, the download location will be <userHome>/Downloads
  2. Extract the tar.gz using tar - if you are in your <userHome>/Downloads, tar will extract to <userHome>/Downloads
  3. Move the extracted folder into a sub-folder of your home folder - so if you extracted it to the <userHome>Downloads/tomcat, you will move it to <userHome>/tomcat
  4. cd to tomcat/bin, ls the contents, there are two files for starting and stopping tomcat: startup.sh and shutdown.sh.  You can either change the permissions of these files so that you can execute them as super user/root
  5. To make life easier for yourself, add <userHome/tomcat/bin to your PATH so that you can execute the tomcat commands from anywhere on the machine 

Alternatively using wget

Installing java

  1. check if you java installed
    1. java -version
  2. if it's not installed run the commands below, otherwise go to installing tomcat
    1. install jdk (must be jdk) using alternatives (this application ensures that you can install several versions of the jdk on your machine)
    2. Install JDK
      cd /opt/
      wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz"
      
      tar xzf jdk-8u91-linux-x64.tar.gz
       
      cd /opt/jdk1.8.0_91/
      alternatives --install /usr/bin/java java /opt/jdk1.8.0_91/bin/java 2
      alternatives --config java
      
      
      There are 3 programs which provide 'java'.
      
        Selection    Command
      -----------------------------------------------
      *  1           /opt/jdk1.7.0_71/bin/java
       + 2           /opt/jdk1.8.0_45/bin/java
         3           /opt/jdk1.8.0_77/bin/java
         4           /opt/jdk1.8.0_91/bin/java
      
      Enter to keep the current selection[+], or type selection number: 4
  3. At this point the JDK should be installed, I now recommend you ensure that javac is available
    1. Install JDK
      alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_91/bin/jar 2
      alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_91/bin/javac 2
      alternatives --set jar /opt/jdk1.8.0_91/bin/jar
      alternatives --set javac /opt/jdk1.8.0_91/bin/javac
  4. Check your java version with
    1. java -version
  5. Setup three very important variables
  6. JAVA_HOME
    1. export JAVA_HOME=/opt/jdk1.8.0_91
  7. JRE_HOME
    export JRE_HOME=/opt/jdk1.8.0_91/jre

     

  8. PATH
    1. export PATH=$PATH:/opt/jdk1.8.0_91/bin:/opt/jdk1.8.0_91/jre/bin

We are now ready to install tomcat

  1. Fetch the version of tomcat you want from apache.org

    Installing Tomcat
    cd /opt
    wget http://www.us.apache.org/dist/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz
    tar xzf apache-tomcat-8.0.27.tar.gz
  2. Configuring Environment variables

  3. Installing Tomcat
    echo "export CATALINA_HOME="/opt/apache-tomcat-8.0.27"" >> ~/.bashrc
    source ~/.bashrc
  4. Starting tomcat
  5. Installing Tomcat
    cd /opt/apache-tomcat-8.0.27
    ./bin/startup.sh

 

<userHome> == ~/

Use the following command to extract from a tar.gz file: tar -xzf <tar.gz file>

Remember some commands can only issued as root, if you log in as root and execute the commands, remember to exit from root and test that what you wanted to happen works as s none root user