July 26, 2012


How To Install Apache Tomcat on Ubuntu 12.04

Tagged In: Ubuntu, Apache, Miscellaneous

About Apache Tomcat

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.

Step One—Install Tomcat

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://mirror.atlanticmetro.net/apache/tomcat/tomcat-7/v7.0.29/bin/apache-tomcat-7.0.29.tar.gz

After the download completes, untar the file.
tar xvzf apache-tomcat-7.0.29.tar.gz

Finish up the Tomcat installation on the VPS by moving the files to a convenient directory.
sudo mv apache-tomcat-7.0.29  ~/path/to/tomcat

Step Two—Install Java

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.

Step Three—Configure .bashrc

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:

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

By Etel Sverdlov

Share this Tutorial

Vote on Hacker News

Try this tutorial on an SSD cloud server.

Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for $5/mo! Learn more

Create an account or login:


Write Tutorial
  • Gravatar maiconfz over 1 year

    Thanks!!! IT WORKS!!! Obs.: You can access the server at [droplet-ip]:8080/ .It's not at localhost:8080/

  • Gravatar Etel Sverdlov over 1 year

    You're totally right! I corrected it above. Thank you!

  • Gravatar kasongoyo over 1 year

    what is droplet-ip? i couldnt run the server

  • Gravatar Etel Sverdlov over 1 year

    Droplet IP refers to your server's IP address. DigitalOcean servers are called Droplets.

  • Gravatar a2165653 over 1 year

    what is ~/path/to/tomcat ? can you explain more? Thanks!

  • Gravatar Etel Sverdlov over 1 year

    This is the extension to where you place your tomcat file. It is different depending on where you choose to install it.

  • Gravatar Server about 1 year

    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!

  • Gravatar John Lussmyer about 1 year

    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?

  • Gravatar neilh20 about 1 year

    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 :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 :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.

  • Gravatar vsc1981 about 1 year

    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.

  • Gravatar rajan0913 about 1 year

    hi .. i have ubuntu 12.04 i am using the eclipse indigo IDE for developing the php projects with the xampp server i want to use the same IDE for develop the JAVAEE project... but i am not able to configure both things PLEASE give me the instructions for those things please help me ! i am waiting for your reply .. thanks in advance !

  • Gravatar neilh20 about 1 year

    Hell vsc1981 - I'm exploring some of these options as well. The way I understand it, tomcat is starting up on machine boot from /etc/init.d/tomcat which sets user:group tomcat6 tomcat6 & CATALINA_HOME=/usr/share/tomcat6 CATALINA_BASE=/var/lib/tomcat6 and it all works. <<>> sudo apt-get install tomcat6-user tomcat6-instance-create my-instance (answer ENTER to the question) Now you can install your common libraries in the lib/ subdirectory and deploy your webapps in the webapps/ subdirectory. No webapps are deployed by default. Now you need to shutdown tomcat and start my-instance my-instance/bin/shutdown.sh my-instance/bin/startup.sh <<<< on startup it unpacks all your webapps/xxxx.war to directory xxxx. now only your deployment of .war is working>>>> HOWEVER, I haven't figured out to do production - get it into the startup $CATALINA_BASE. This is supposed to be easy through the "manager" package - but it hasn't worked for me. Maybe because I don't have the right directory IDs for tomcat6.

  • Gravatar neilh20 about 1 year

    Oops - in the previous post - I'm using tomcat6 because of a legacy app working in it - so every thing should reference tomcat6, and my guess is tomcat7 works the same.

  • Gravatar manpreetsidhu88m 10 months

    Its good........... But where is script to start Apache automatically at Boot time?

  • Gravatar Kamal Nasser 10 months

    @manpreetsidhu88m do /etc/init.d/tomcat and /etc/init.d/apache2 exist?

  • Gravatar 2011chandan 10 months

    I have installed tomcat7. I followed the exact process described here for installation. I have given the path in bash as CATALINA_HOME=/usr/share/tomcat7. But when I'm trying to activate it using CATALINA_HOME/bin/startup.sh, it throws No such file or directory found. Below are the paths that I have set in bash file: export JAVA_HOME=/usr/lib/jvm/default-java export CATALINA_HOME=/usr/share/tomcat7 Can anyone let me why it is happening?

  • Gravatar Kamal Nasser 10 months

    @2011chandan Try running /usr/share/tomcat7/bin/startup.sh directly - does that work?

  • Gravatar mseanu 9 months

    Tell Me to configure Tomcat with php

  • Gravatar Kamal Nasser 9 months

    @mseanu: PHP 5 is not supported by Tomcat. Tomcat is a java webserver, try installing Apache or Nginx to serve PHP files: apache: https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu or nginx: https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04

  • Gravatar klimatima 9 months

    n00b question: i have installed tomcat on my localhost (ubuntu12.04). i can run a war file and so forth. and can then access it ....:8080. so, installing it on DO (it should be similar to how i set it up on my localhost), how then would users be able to view the app? by going to (e.g. droplet_.com:8080) on their browser?

  • Gravatar Kamal Nasser 9 months

    @klimatima: Yes, that is correct.

  • Gravatar bezvezemail 9 months

    I dont get a page like from a picture. I get "It works If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!.." but how do I get the page from the picture?

  • Gravatar Kamal Nasser 9 months

    @bezvezemail: This article is a bit old so Tomcat might have changed their default page.

  • Gravatar sandeepbhandari1 9 months

    Could you pls. also share what if we are unable to start tomcat due to some problem and still want to know the version of tomcat by being offline. I have searched a lot for this but not able to find a way. The other tutorial also proved of some help but still looking for answer.

  • Gravatar Kamal Nasser 9 months

    @sandeepbhandari1: "apt-cache show tomcat7" should show you the package's version.

  • Gravatar klimatima 8 months

    i also installed tomcat6 and when i run the "$CATALINA_HOME/bin/startup.sh" i get this: -bash: /root/usr/share/tomcat6/bin/startup.sh: No such file or directory but when i go to 8080, i see the "it works" page, but that's all. going to the manager webapp throws a 404 error.

  • Gravatar Kamal Nasser 8 months

    @klimatima: Did you follow this article properly? Please paste the commands you ran (they're stored in ~/.bash_history).

  • Gravatar nishapmore 8 months

    Hi, I followed all the steps you have given. For more clarification: I run below commands , 1) sudo apt-get install tomcat7 ( I am successfully installed tomcat7 @ user/share/tomcat7) 2) sudo apt-get install default-jdk ( Successful java installed @ /usr/lib/jvm/default-java) 3) sudo nano ~/.bashrc ( export JAVA_HOME=/usr/lib/jvm/default-java export CATALINA_HOME=/user/share/tomcat7 added at end of file and saved) 4)~/.bashrc when i hit the enter after this cmd I got an error Permission denied:( 5)$CATALINA_HOME/bin/startup.sh then I got "bash: CATALINA_HOME/bin/startup.sh: No such file or directory " 6) According to post i ran "/usr/share/tomcat7/bin/startup.sh" and this time I got below Error log on terminal. shani@shani-Vostro-2520:~$ /usr/share/tomcat7/bin/startup.sh Using CATALINA_BASE: /usr/share/tomcat7 Using CATALINA_HOME: /usr/share/tomcat7 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp Using JRE_HOME: /usr/lib/jvm/default-java Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar touch: cannot touch `/usr/share/tomcat7/logs/catalina.out': No such file or directory /usr/share/tomcat7/bin/catalina.sh: 389: /usr/share/tomcat7/bin/catalina.sh: cannot create /usr/share/tomcat7/logs/catalina.out: Directory nonexistent Please Help me!!!

  • Gravatar Kamal Nasser 7 months

    @nishapmore: Are you still experiencing this issue?

  • Gravatar petersonjake 7 months

    export CATALINA_HOME=/user/share/tomcat7 I created the directory "logs" as well as the file "catalina.out" inside it..... droplet-ip:8080: ******************* It works ! If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations! This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/ROOT/index.html

  • Gravatar Kamal Nasser 7 months

    Great! :]

  • Gravatar normanitc 7 months

    I've been working for hours trying to get this to work. If I start up a completely new droplet, it get it to work every time, first try. However when I try to do this on my droplet that I've already set up with a LAMP stack, and already have a website running with a mail server, owncloud and all that I always get the error when I try to run $CATALINA_HOME/bin/startup.sh. The error is: -bash: /root/usr/share/tomcat7/bin/startup.sh: No such file or directory This is following the setup exactly. And like I said when I run this on a fresh droplet it works fine.

  • Gravatar normanitc 7 months

    After doing research I probably should have done before, do you still have to do some config. to use apache2 with tomcat7?

  • Gravatar Kamal Nasser 7 months

    @normanitc: See if this helps: http://thetechnocratnotebook.blogspot.co.il/2012/05/installing-tomcat-7-and-apache2-with.html

  • Gravatar ichraf.bouzekri 6 months

    Hi nishapmore, I have the same problem. Could you tell me if you have risolved it ??

  • Gravatar ayoubpats 6 months

    Hi i have installed tomcat7 and openjdk and when i run the below command it says no such file or directory CATALINA_HOME/bin/startup.sh -bash: CATALINA_HOME/bin/startup.sh: No such file or directory root@pacific:~# usr/share/tomcat7/bin/startup.sh -bash: usr/share/tomcat7/bin/startup.sh: No such file or directory when i goto my ipadress:8080 it gives the below mesage .dont know if i can go ahead and deploy my application or not. It works ! If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations! This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/ROOT/index.html Tomcat7 veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HOME in /usr/share/tomcat7 and CATALINA_BASE in /var/lib/tomcat7, following the rules from /usr/share/doc/tomcat7-common/RUNNING.txt.gz. You might consider installing the following packages, if you haven't already done so: tomcat7-docs: This package installs a web application that allows to browse the Tomcat 7 documentation locally. Once installed, you can access it by clicking here. tomcat7-examples: This package installs a web application that allows to access the Tomcat 7 Servlet and JSP examples. Once installed, you can access it by clicking

  • Gravatar Kamal Nasser 6 months

    @ayoubpats: It should be $CATALINA_HOME/bin/startup.sh, not CATALINA_HOME/bin/startup.sh

  • Gravatar ivelclown 6 months

    Guys, is the procedure the same in installing apache2 in red hot?

  • Gravatar Kamal Nasser 6 months

    @ivelclown: No. This article walks you through installing Apache Tomcat on Ubuntu. See https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6 on how to install Apache2 on CentOS.

  • Gravatar jamesharoldkelley 6 months

    I ***STRONGLY*** suggest that users also setup CATALINA_BASE environment var while configuring CATALINA_HOME in their .bashrc file as follows: CATALINA_HOME=/usr/share/tomcat7 CATALINA_BASE=/var/lib/tomcat7 CATALINA_BASE contains various configurations that are NOT properly picked up (if unset) since CATALINE_BASE defaults to the same path as CATALINA_HOME and things get very wonky, this would including: startup errors, unable to find logging directories and doing something as simple as changing Tomcat port from 8080 to 80 will fail miserably because the autobind property (contained in a configuration file in /var/lib/tomcat7) will be missing/improperly set. Might I suggest that this additional step be included in the above how-to. (BTW -- figuring this all out took several hours after pouring over the tomcat manuals before stumbling onto this, while some might have found it faster, I don't think it is at all obvious for any newbie) Thanks

  • Gravatar vishal 5 months

    Hi, My Tomcat Server keeps on crashing everytime I delete a webapp or restart tomcat In order to restart tomcat I use the following command - sudo service tomcat7 restart Can someone please help

  • Gravatar Kamal Nasser 5 months

    @vishal: Does it output any errors when it crashes?

  • Gravatar enterhtml 5 months

    Hi I'm new to this kind of installation. I followed all the three steps exactly. But in the forth step, I don't know what to do. I gave the path for "export CATALINA_HOME=~/path/to/tomcat" as "export CATALINA_HOME=~/home/MY_Name/tomcat". Now please tell me how to run $CATALINA_HOME/bin/startup.sh? I enter the same "$CATALINA_HOME/bin/startup.sh" on my terminal. It didn't work. Where to run or add this link. Please help.

  • Gravatar bharath.shanigarpu 5 months

    I have installed tomcat 7..i want to add it in startup script..how to i add it... Thanks in advance

  • Gravatar Kamal Nasser 5 months

    Does /etc/init.d/tomcat exist?

  • Gravatar mattbaker 3 months

    @Kamal Nasser: I'm getting the error: touch: cannot touch `/usr/share/tomcat7/logs/catalina.out': No such file or directory /usr/share/tomcat7/bin/catalina.sh: 389: /usr/share/tomcat7/bin/catalina.sh: cannot create /usr/share/tomcat7/logs/catalina.out: Directory nonexistent Any thoughts on fixing this are appreciated by me and the others who have posted this error on this thread. Thank you!!!

  • Gravatar jagad1978 about 1 month

    How can we setup tomcat to auto start on server reboot? I installed tomcat in root (/root/apache-tomcat-7.0.52/) Can someone please help Thanks, Jagadish

  • Gravatar nguyen.h.khanh about 1 month

    I downloaded and extract tomcat to /opt/. I was able to start tomcat but when I tried to access myip:8080, there is nothing. In fact, it's an error. Chrome says it can't connect. My terminal looks like: knguyen@knguyen:~$ $CATALINA_HOME/bin/startup.sh Using CATALINA_BASE: /opt/tomcat8 Using CATALINA_HOME: /opt/tomcat8 Using CATALINA_TMPDIR: /opt/tomcat8/temp Using JRE_HOME: /usr/bin/ Using CLASSPATH: /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar Tomcat started.

  • Gravatar rock.and.roses 20 days

    hi, dont work me CATALINA'S setup or run it on terminal, but on browser i wrote http://localhost:8080/ previusly on terminal : sudo /etc/init.d/tomcat7 start [sudo] password for user: xxxxxx * Starting Tomcat servlet engine tomcat7 and: It works ! If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations! This is the default Tomcat h........ it is all right? or...?

Leave a Comment

Create an account or login: