In this post:

  • Install Tomcat 8 with apt-get
    • Step 1 - Install Tomcat
    • Step 2 - Setup Tomcat
    • Step 3 - Installing Additional Packages
    • Step 4 - Configure Tomcat Web Management Interface
    • Step 5 - Restart to complete your installation
    • Step 6: Test configuration by Web Interface
  • Install binary distribution
    • Step 1 - Prerequisites
    • Step 2: Tomcat User creation
    • Step 3: Install Tomcat 8
    • Step 4: Update Permissions
    • Step 5: Configure Tomcat Web Management Interface
    • Strp 6: Restart
    • Step 7: Test configuration by Web Interface

There are two basic ways to install Tomcat on Ubuntu:

  • Install through apt-get. This is the simplest method.
  • Download the binary distribution from the Apache Tomcat site.

Install through apt-get

Step 0 - Prerequisites

sudo apt-get update
sudo apt-get install default-jdk

Step 1 - Install Tomcat

sudo apt-get update
sudo apt-get install tomcat8

Step 2 - Setup Tomcat

sudo nano /etc/default/tomcat8

Change java settings — JAVA_OPTS in /etc/default/tomcat8

JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC"

Now restart Tomcat with this command:

sudo service tomcat8 restart

Step 3 - Installing Additional Packages

sudo apt-get install tomcat8-docs tomcat8-admin tomcat8-examples

Step 4 - Configure Tomcat Web Management Interface

sudo nano /etc/tomcat8/tomcat-users.xml
<tomcat-users>
   <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>

Step 5 - Restart to complete your installation

sudo service tomcat8 restart

Step 6: Test configuration by Web Interface

http://server_domain_or_IP:8080

Install binary distribution

Step 1 - Prerequisites

sudo apt-get update
sudo apt-get install default-jdk

Step 2: Tomcat User creation

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Step 3: Install Tomcat 8

curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

Step 4: Update Permissions

cd /opt/tomcat
sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps/ work/ temp/ logs/

Step 5 - Configure Tomcat Web Management Interface

sudo nano /etc/tomcat8/tomcat-users.xml
<tomcat-users>
   <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>

Step 6 - Restart to complete your installation

sudo service tomcat8 restart

Step 7: Test configuration by Web Interface

http://server_domain_or_IP:8080