This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
Apache tomcat is a Java based application server released by the Apache Software Foundation. It is a web server and a servlet container for Java web applications.
Tomcat installation on a virtual private server is relatively easy. Its single required dependency is Java and this tutorial will include a step on how to install that platform.
You do need to have a user with sudo privileges for this tutorial.
The most recent version of Tomcat is 7, and it can be easily downloaded through apt-get or from the Apache Tomcat site.
You can download it through apt-get by typing:
sudo apt-get install tomcat7
To download tomcat from their site, copy the link for the tar.gz package under the “Core” section and begin the download. You will get a link that originates from one of Apache’s many mirrors, making the command look mostly like this (although coming from a different site).
wget http://apache.mivzakim.net/tomcat/tomcat-7/v7.0.57/bin/apache-tomcat-7.0.57.tar.gz
After the download completes, untar the file.
tar xvzf apache-tomcat-7.0.57.tar.gz
Finish up the Tomcat installation on the VPS by moving the files to a convenient directory.
sudo mv apache-tomcat-7.0.57 ~/path/to/tomcat
We installed the entire Apache Tomcat server on our virtual server in the previous step. Before we can use it, however, we do need to have Java installed on the VPS as well. If you currently do not have java, you can download it quite easily with apt-get.
sudo apt-get install default-jdk
Once you have Tomcat and Java installed on the virtual private server, all that remains is to start them.
In order to start Tomcat, we need to add it as an environment variable in the /.bashrc file.
sudo nano ~/.bashrc
You can add this information to the end of the file:
export JAVA_HOME=/usr/lib/jvm/default-java
export CATALINA_HOME=~/path/to/tomcat
Save and exit out of .bashrc. You can make the changes effective by restarting the bashrc file.
. ~/.bashrc
Tomcat is now installed and configured on our virtual servers. However, it is not yet activated.
The final step is to activate Tomcat by running its startup script:
$CATALINA_HOME/bin/startup.sh
Once that runs, Tomcat is up and ready on port 8080.
You can visually verify that Tomcat is working by accessing your server page at your_IP_address:8080.
It should look like this
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks!!! IT WORKS!!!
Obs.: You can access the server at [droplet-ip]:8080/ .It’s not at localhost:8080/
You’re totally right! I corrected it above. Thank you!
what is droplet-ip? i couldnt run the server
Droplet IP refers to your server’s IP address. DigitalOcean servers are called Droplets.
what is ~/path/to/tomcat ? can you explain more? Thanks!
This is the extension to where you place your tomcat file. It is different depending on where you choose to install it.
Thank you for the notes. Could you explain why this tutorial did not just use apt-get to install the tomcat7 package? Also, how can we setup tomcat to auto start on server reboot?
Thanks!
I used the “sudo apt-get install tomcat7”, and it installed tomcat to /usr/share/tomcat7 It also installed the openjdk version of Java. I did have to edit the .bashrc to add the 2 settings. I also needed to set CATALINA_OUT=/var/log/tomcat7/catalina.out The problem is that tomcat then complains it doesn’t have permission to write there. How do I change the permissions on the /var/log/tomcat7 directory?
I used the “sudo apt-get install tomcat6”, and it installed tomcat to /usr/share/tomcat6 There was already installed an OpenJdk IcedTea6 1.12.3 java version “1.6.0_27” When I did startup.sh - I had the same response touch: cannot touch `/usr/share/tomcat6/logs/catalina.out’: No such file or directory /usr/share/tomcat6/bin/catalina.sh: 375: /usr/share/tomcat6/bin/catalina.sh: cannot create /usr/share/tomcat6/logs/catalina.out: Directory nonexistent
However, trying <droplet_ip>:8080 I got “It worked” for tomcat - so something is coming up. So creating and fixing the sudo mkdir /usr/share/tomcat6/logs sudo chown user:user /usr/share/tomcat6/logs Allowed me to cat /usr/share/tomcat6/logs/catalina.out and a few other directories needed creating and populating which got me into more issues. Then <droplet_ip>:8080 didn’t even respond.
Seems to me that the basic configuration doesn’t pull in a working demo - and I’m going back to thinking about it. I do have a working/production tomcat6 environment on another virtual machine (that some one else setup), and got a version up and going on a local Ubuntu 11.x some time ago - so going to figure out what I did in those environments.
Hi! I have to install Tomcat in order to run my WAR file. I have installed it using “sudo apt-get install tomcat7”. Because of the posts above I have discovered the path where it has been installed is: “/usr/share/tomcat7” I have added to “sudo nano ~/.bashrc” the 2 lines you specify. When I try to run the “$CATALINA_HOME/bin/startup.sh” command it tells me: “/home/MYUSER/usr/share/tomcat7/bin/startup.sh: No such file or directory” It adds the “/home/MYUSER/” string to the path and I cannot execute the startup.sh, but for some reason if write DROPLET_IP:8080 on my browser the tomcat page appears and it seems to work. Can you help me with this please? Thanks in advance.