LinuxTutorialsUbuntu

How To Install Apache Tomcat 8 on Ubuntu 16.04

Install Apache Tomcat 8 on Ubuntu 16.04

In this tutorial, we will show you how to install and configuration of Apache Tomcat 8 on your Ubuntu 16.04 server. For those of you who didn’t know, Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation. It implements the Java Servlet, JavaServer Pages (JSP), Java Unified Expression Language, and Java WebSocket specifications from Sun Microsystems and provides a web server environment for Java code to run in.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Apache Tomcat 8 on a Ubuntu 16.04 LTS (Xenial Xerus) server.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 16.04 LTS (Xenial Xerus).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Apache Tomcat 8 on Ubuntu 16.04

Step 1. Installing Java (JRE or JDK).

Once you have verified if Java is installed or not, choose the type of Java installation that you want with one of the following:

sudo apt-get install openjdk-7-jre
sudo apt-get install openjdk-7-jdk

Another alternative Java install is with Oracle JRE and JDK. However, we would need to install additional repositories for proper installation:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java

Then, you will need to fully update the system with the following command and install it:

sudo apt-get update
sudo apt-get install oracle-java8-installer

Verify Installed Java Version.

java -version

Result:

java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

Setup JAVA_HOME on Ubuntu 16.04.

Since many programs nowadays need a JAVA_HOME environment variable to work properly. We will need to find the appropriate path to make these changes. With the following command, you can view your installs and their path:

sudo update-alternatives --config java
sudo nano /etc/profile

Now that you are in the user profile file, add the following code, along with the Path of your installation from the previous step, to the bottom. ( Example: JAVA_HOME=”YOUR_PATH”):

export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51-1.b16.el7_1.x86_64"

Reload the file so all your changes could take effect with the following command:

source /etc/profile

Verify that your implementations are correct with the following command:

echo $JAVA_HOME

Step 2. Installing Apache Tomcat.

The first thing to do is to go to Apache Tomcat’s download page and download the latest stable version of Apache Tomcat, At the moment of writing this article it is version 8:

cd /opt
wget http://a.mbbsindia.com/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0.35.zip
tar -xvf apache-tomcat-8.0.35.zip

Add tomcat user and group:

ln -s /opt/apache-tomcat-8.0.35 /opt/tomcat-latest
chown -hR tomcat8: /opt/tomcat-latest /opt/apache-tomcat-8.0.35

Step 3. Configure environment variables.

Before starting Tomcat, configure the CATALINA_HOME environment variable in your system using the following commands.

# echo "export CATALINA_HOME=\"apache-tomcat-8.0.35\"" >> ~/.bashrc
# source ~/.bashrc

Step 4. Configure Tomcat to run as a service.

cd /opt/apache-tomcat-8.0.35/bin
./startup.sh

You will get the following output.

Using CATALINA_BASE:   /var/local/apache-tomcat-8.0.35
Using CATALINA_HOME:   /var/local/apache-tomcat-8.0.35
Using CATALINA_TMPDIR: /var/local/apache-tomcat-8.0.35/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /var/local/apache-tomcat-8.0.35/bin/bootstrap.jar:/var/local/apache-tomcat-8.0.35/bin/tomcat-juli.jar
Tomcat starte

You can verify the service running, by default tomcat runs on port no 8080.

[root@idroot ~]# netstat -antup | grep 8080
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN

Step 5. Finally, open Tomcat from your browser, go to your IP or domain with the 8080 port (because Tomcat will always run on the 8080 port) as an example: mydomain.com:8080, replace mydomain.com with your IP or domain.

To shutdown Tomcat you can simply run the shutdown script in the same folder like this:

/opt/apache-tomcat-8.0.35/bin/shutdown.sh

Step 6. Setup user accounts.

Configure Tomcat users so they can access admin/manager sections. You can do this by adding the users in the conf/tomcat-users.xml file with your favorite text editor. Add this text to the file:

nano /opt/apache-tomcat-8.0.35/conf/server.xml

Place the following two lines just above the last line.

<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />

<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />

Save and close the file when you are finished. To put our changes into effect, restart the Tomcat service:

systemctl restart tomcat

Congratulations! You have successfully installed Apache Tomcat. Thanks for using this tutorial for installing Apache Tomcat 8 in Ubuntu 16.04 LTS system. For additional help or useful information, we recommend you check the official Apache Tomcat website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button