Install Jenkins on Tomcat Server

Install Jenkins on Tomcat Server

Play this article

Step 1: Install Java

Tomcat requires Java to be installed on the server so that any Java web application code can be executed. We can satisfy that requirement by installing OpenJDK with apt-get. First, update your apt package index:

$ sudo apt update -y

Then install the Java Development Kit package with apt:

$ sudo apt install openjdk-8-jdk -y

Step 2: Install Tomcat

The best way to install Tomcat 8 is to download the latest binary release then configure it manually.

Find the latest version of Tomcat 8 at the Tomcat 8 Downloads page. At the time of writing, the latest version is 8.5.85, but you should use a later stable version if it is available. Under the Binary Distributions section, then under the Core list, copy the link to the “tar.gz”.

Next, change to the /tmp directory on your server. This is a good directory to download ephemeral items, like the Tomcat tarball, which we won’t need after extracting the Tomcat contents:

$ cd /tmp

Use wget to download the link that you copied from the Tomcat website:

$ wget

We will install Tomcat to the /opt/tomcat directory. Create the directory, then extract the archive to it with these commands:

$ sudo mkdir /opt/tomcat
$ sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat - strip-components=1

Step 3: Update Permissions

The current user that we set up needs to have access to the Tomcat installation. We’ll set that up now.

Change to the directory where we unpacked the Tomcat installation:

$ cd /opt/tomcat 
$ sudo chown -R ubuntu:ubuntu /opt/tomcat

Step 4: Create a systemd Service File

We want to be able to run Tomcat as a service, so we will set up systemd service file.

Tomcat needs to know where Java is installed. This path is commonly referred to as “JAVA_HOME”. The easiest way to look up that location is by running this command:

sudo update-java-alternatives -l
java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64

The correct JAVA_HOME variable can be constructed by taking the output from the last column and appending /jre to the end. Given the example above, the correct JAVA_HOME for this server would be:


Your JAVA_HOME may be different.

With this piece of information, we can create the systemd service file. Open a file called tomcat.service in the /etc/systemd/system directory by typing:

$ sudo vi /etc/systemd/system/tomcat.service

Paste the following contents into your service file. Modify the value of JAVA_HOME if necessary to match the value you found on your system. You may also want to modify the memory allocation settings that are specified in CATALINA_OPTS:


Description=Apache Tomcat Web Application Container
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'

When you are finished, save and close the file.

Next, reload the systemd daemon so that it knows about our service file:

$ sudo systemctl daemon-reload

Start the Tomcat service by typing:

sudo systemctl start tomcat

Double check that it started without errors by typing:

$ sudo systemctl status tomcat

Step 5 : Download jenkins stable version war file

find the latest version of jenkins at War Jenkins Packages , Download the jenkins war file using wget command

$ cd /tmp
$ wget

Deploy download jenkins war file into tomcat webapps folder

$ sudo cp jenkins.war /opt/tomcat/webapps/

Restart tomcat service

$ sudo systemctl restart tomcat

Hit the tomcat url in your web browser ip-address:8080/jenkins

Did you find this article valuable?

Support Naveen Elwaka by becoming a sponsor. Any amount is appreciated!