This wikiHow teaches you how to download, set up, and start an Apache Tomcat web server environment on your computer, using an Ubuntu Linux system. Apache Tomcat is an open-source, Java-based HTTP web server environment. You can implement several Java EE specifications including Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies in Tomcat.[1]

Part 1
Part 1 of 2:

Setting Up Tomcat

  1. 1
    Open a Terminal window on your Ubuntu machine. Click the Dash icon on the top-left, and click Terminal on the app list to open the Terminal.
    • Alternatively, press Ctrl+Alt+T on your keyboard to open the Terminal.
  2. 2
    Type sudo apt-get update in Terminal. This command will update all your repositories, and make sure you have the latest software versions for new installations.
    Advertisement
  3. 3
    Press Enter or Return on your keyboard. This will run the command, and update your repositories.
  4. 4
    Run sudo apt-get install default-jdk in Terminal. This will install the latest version of the official Java Development Kit on your computer.
    • Type or paste the command, and press Enter or Return to run it.
    • You'll need Java installed on your computer to install and set up Tomcat.
    • If you already have Java installed, this will update it to the latest version.
    • You can skip this step if you already have the latest Java version installed.
  5. 5
    Run sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat in Terminal. This will create a new system user, and group with home directory opt/tomcat to run the Tomcat service.
    • You cannot run the Tomcat service under the root user for your server's security purposes.
  6. 6
    Open the Tomcat website in your internet browser. Type or paste http://tomcat.apache.org into your browser's address bar, and press Enter or Return on your keyboard.
  7. 7
    Click the Tomcat version you want under "Download" on the left sidebar. You'll find the available Tomcat version on a navigation menu on the left-hand side of the page. You can select Tomcat 9 or another version here.
    • If you want to see which versions are compatible with your system, click Which version? under the Download heading here.
  8. 8
    Right-click the blue tar.gz link under the "Core" heading. This will open your right-click options on a drop-down menu.
  9. 9
    Click Copy Link Address from the right-click menu. You can directly install Tomcat with the TAR file's link address here.
  10. 10
    Type wget <link address> into the Terminal. This will allow you to download the latest version of Tomcat to your computer from the official download link.
    • Replace <link address> with the link address you copied from the official Apache Tomcat website.
  11. 11
    Press Enter or Return. This will run the download command, and download Tomcat on your computer.
  12. 12
    Run sudo tar xf /tmp/apache-tomcat-9*.tar.gz -C /opt/tomcat. Once your download is complete, run this command to extract the downloaded TAR file's contents, and move the files to the opt/tomcat directory.
    • Make sure to replace the version number in "tomcat-9*.tar.gz" with the Tomcat version you download.
  13. 13
    Run sudo nano /etc/systemd/system/tomcat.service. This will create a new file named "tomcat.service," and allow you to edit its contents with your default text editor.
  14. 14
    Paste the following configuration into the tomcat.service file.
    • Make sure to set "JAVA_HOME" to your system's Java directory in the following code.
    • [Unit]
      Description=Apache Tomcat Web Application Container
      After=network.target
      
      [Service]
      Type=forking
      
      Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
      Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
      Environment=CATALINA_HOME=/opt/tomcat
      Environment=CATALINA_BASE=/opt/tomcat
      Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
      Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
      
      ExecStart=/opt/tomcat/bin/startup.sh
      ExecStop=/opt/tomcat/bin/shutdown.sh
      
      User=tomcat
      Group=tomcat
      UMask=0007
      RestartSec=10
      Restart=always
      
      [Install]
      WantedBy=multi-user.target
      
  15. Advertisement
Part 2
Part 2 of 2:

Starting Tomcat Service

  1. 1
    Run sudo systemctl daemon-reload in Terminal. This will reload the SystemD daemon, and find your new service file.
  2. 2
    Run the sudo ufw allow 8080 command (optional). If your server is protected by a firewall, run this command in Terminal to allow traffic on port 8080.
    • This will allow you to access the Tomcat interface from outside of your local network.
  3. 3
    Run the systemctl enable tomcat command (optional). If you run this command, Tomcat service will automatically start on system boot.
  4. 4
    Run sudo systemctl start tomcat in Terminal. This will start the Tomcat service on your server.
    • You can use the sudo systemctl status tomcat command to verify the service status.
    • You can now test Tomcat in your internet browser at http://ip-address:8080. Just change "ip-address" with your system's default IP address in the link.
  5. Advertisement

About This Article

wikiHow Staff
Co-authored by:
wikiHow Staff Writer
This article was co-authored by wikiHow Staff. Our trained team of editors and researchers validate articles for accuracy and comprehensiveness. wikiHow's Content Management Team carefully monitors the work from our editorial staff to ensure that each article is backed by trusted research and meets our high quality standards. This article has been viewed 10,138 times.
How helpful is this?
Co-authors: 6
Updated: May 21, 2021
Views: 10,138
Categories: Ubuntu
Article SummaryX

1. Install and update Java on your computer.
2. Open a Terminal window.
3. Run "sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat."
4. Open the Tomcat website, and click a version on the left menu.
5. Right-click tar.gz under "Core," and click Copy Link Address.
6. Run "wget " with the copied link.
7. Run "sudo tar xf /tmp/apache-tomcat-9*.tar.gz -C /opt/tomcat."
8. Run "sudo nano /etc/systemd/system/tomcat.service."
9. Paste the configuration code into "tomcat.service," and start Tomcat.

Did this summary help you?
Advertisement