Install Tomcat 9 on Ubuntu-A complete tutorialIn this tutorial, we will teach you how to install Tomcat 9 on Ubuntu 16.04.
Apache TomcatApache Tomcat, previously known for Jakarta Tomcat or just Tomcat, is an open source web server servlet container developed by the Apache Software Foundation. It runs Java servlets and renders Web pages which include Java Server Page coding and is one of the most popular web servers used by Java developers. Want to learn More about VPS Hosting; we hand-picked guides for you;
Install Tomcat 9 on Ubuntu 16.04In this tutorial, you are going to install the latest release of Tomcat 9 server on an Ubuntu 16.04 VPS. This guide will work on other Debian based systems, however, it was made and tested for Ubuntu 16.04.
Step 1: Log into the Server via SSH.First, log into the Ubuntu 16.04 VPS via SSH as user root.
ssh [email protected]_address
Step 2: Initiate a new screen session.
screen -U -S tomcat9
Step 3: Updating All System Packages.In order to update the packages installed on your server, execute the command below in the terminal.
apt-get update && apt-get upgrade
Step 4: Installing JavaIf you want to run the Tomcat server then Java needs to be installed on the VPS. Run the command below to Install the Java Development Kit package (JDK).
apt-get install default-jdkOnce the installation is finished. You can check if Java was installed on the server using the following command.
java -versionIf you get an output similar to the one below, the installation was successful.
openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)After Java is installed on the server, you can continue installing Tomcat 9.
Step 5: Install and Configure Tomcat 9.For security reasons, we recommend that you do not run Tomcat as user root. For this reason, you must create a new system user.
useradd -r tomcat9 --shell /bin/falseChange the current working directory to ‘/opt’ and download the latest Tomcat 9 release to the ‘/opt’ directory on your server. When this tutorial was made, the latest Tomcat version was 9.0.0.M6. You will need to go to Tomcat’s official website to check if there is a newer version available.
cd /opt wget http://mirror.symnds.com/software/Apache/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gzExtract the content of the archive into a directory.
tar -zxf apache-tomcat-9.0.0.M6.tar.gzNow create a symbolic link for the Tomcat directory to ‘/opt/tomcat-latest’ and set the appropriate ownership.
ln -s apache-tomcat-9.0.0.M6 tomcat-latest chown -hR tomcat9: tomcat-latest apache-tomcat-9.0.0.M6Tomcat can now be started, stopped and restarted using the bash scripts located in the ‘/opt/tomcat-latest/bin’ directory or, even better, you can just create a ‘system init’ file for this purpose.
nano /etc/systemd/system/tomcat.serviceAppend the following content to the file:
[Unit] Description=Tomcat9 After=network.target [Service] Type=forking User=tomcat9 Group=tomcat9 Environment=CATALINA_PID=/opt/tomcat-latest/tomcat9.pid Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 Environment=CATALINA_HOME=/opt/tomcat-latest Environment=CATALINA_BASE=/opt/tomcat-latest Environment="CATALINA_OPTS=-Xms512m -Xmx512m" Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC" ExecStart=/opt/tomcat-latest/bin/startup.sh ExecStop=/opt/tomcat-latest/bin/shutdown.sh [Install] WantedBy=multi-user.targetSave the file, reload the system daemon, and start the Tomcat server before enabling it to start on boot.
systemctl daemon-reload systemctl start tomcat systemctl enable tomcat
Final ThoughtsLastly, if you have closely followed the steps above, you should be able to access Tomcat by using a web browser of your choosing and going to ‘http://your_server_IP:8080′. One more thing… We have hand-picked hosting, security, CMS and Linux guides for them;
Updated on 11 Sep 2018
Add a comment