/
How to install Tomcat
How to install Tomcat
Step-by-step guide
- Download tomcat from http://tomcat.apache.org/download-70.cgi - if you do this from a browser, the download location will be <userHome>/Downloads
- Extract the tar.gz using tar - if you are in your <userHome>/Downloads, tar will extract to <userHome>/Downloads
- 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
- 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
- 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
- check if you java installed
- java -version
- if it's not installed run the commands below, otherwise go to installing tomcat
- install jdk (must be jdk) using alternatives (this application ensures that you can install several versions of the jdk on your machine)
- 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
- At this point the JDK should be installed, I now recommend you ensure that javac is available
- 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
- Check your java version with
- java -version
- Setup three very important variables
- JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_91
JRE_HOME
export JRE_HOME=/opt/jdk1.8.0_91/jre
- PATH
export PATH=$PATH:/opt/jdk1.8.0_91/bin:/opt/jdk1.8.0_91/jre/bin
We are now ready to install tomcat
Fetch the version of tomcat you want from apache.org
Installing Tomcatcd /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
Configuring Environment variables
- Installing Tomcat
echo "export CATALINA_HOME="/opt/apache-tomcat-8.0.27"" >> ~/.bashrc source ~/.bashrc
- Starting tomcat
- 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
Related articles