In this article, I’d like to share the detailed steps about how to download, install, configure and run Apache Tomcat server on Mac operating system (macOS).

Tomcat is a free and open-source Java web server developed by the Apache Software Foundation. It’s widely used by developers to run web applications built on Java EE platform.

 

Why Tomcat version 9???

Tomcat version 9 requires Java 8 or later, and it supports the following Java EE technologies: Servlet 4.0, JSP 2.3, EL 3.0, WebSocket 1.1, Authentication (JASPIC) 1.1, … that means Tomcat 9 can be used for running Java web applications built with Java 8 or later and Servlet 4.0 or older.

NOTE: Java Development Kit (JDK) is required to run Tomcat because this server software program is built in Java. Check this article to setup JDK on macOS.

 

1. Download binary distribution of Tomcat 9

Tomcat 9 is distributed as archive file (zip or tar.gz) for macOS so we need to download and install manually. Click this link to head over to Tomcat 9’s official download page. Look at the Binary Distributions section:

download tomcat 9 archive file



Click the “zip” link (1) to download. You’ll get the file apache-tomcat-9.0.x.zip downloaded on your computer.

NOTE: You may choose another mirror site for download, so checking SHA512 of the downloaded file is recommended.


2. Install Tomcat 9 on macOS

You should verify integrity of the downloaded zip file because it can be transferred from a mirror site, to make sure it is safe to use (not tampered). Open a new Terminal window, change the current directory to where the zip file is downloaded. Then type the following command:

shasum -a 512 apache-tomcat-9.0.82.zip

You should get the following SHA512 checksum of the file as shown below:

checksum zip file of Tomcat 9

On the download page, click the “sha512” link (2) next to download link, then compare the published SHA512 value against the one calculated by the shasum command. If both are identical, that means you’re safe to use the archive file.

To install, extract the zip file into a specific folder, e.g. user home directory, using the following command:

tar -xf apache-tomcat-9.0.82.zip -C $HOME

Then perform some cd and ls commands to see the files extracted:

listing files of Tomcat 9

You can see some shell script files (.sh) in the bin directory. These scripts can be used to control the server (start, stop, debug…). Here I name the primary ones:

  • catalina.sh: this is the general purpose script that can be used to check version, start, stop, debug the server…
  • version.sh: a shortcut to see version of the server, OS, JVM
  • startup.sh: a shortcut to start the server
  • shutdown.sh: a shortcut to stop the server
Next, let’s see how to start and stop Tomcat using shell scripts.


3. Start Tomcat server

Make sure that bin is the current directory, type the following command in terminal to start Apache Tomcat 9 server:

./catalina.sh start

This will run the server in a background thread. You should see the following output:

start Tomcat 9 command

That means Tomcat has started. The server is listening on port 8080 (default port number of Tomcat) and is ready to receive requests. Now, open your web browser, and enter http://localhost:8080 into the address bar, you’ll see the server’s home page as shown below:

testing Tomcat 9 localhost

Congratulations! You have installed Tomcat 9 successfully on your macOS. This web interface allows you to deploy, manage, monitor Java web applications running on the server. Learn more: How to deploy a Java web application on Tomcat.

NOTES:

You can also use the following commands in Terminal to start Tomcat:

  • sh catalina.sh start
  • sh startup.sh
  • ./startup.sh
If you get permission denied error when running these scripts, you need to grant execute permission to the current user using the following command:

chmod u+x catalina.sh

chmod u+x startup.sh


4. Stop Tomcat server

To shut down the running server, you can run the following command:

./catalina.sh stop

Tomcat will be stopped, as shown below:

stop Tomcat 9 command

NOTES:

You can also use the following commands in Terminal to start Tomcat:

  • sh catalina.sh stop
  • sh shutdown.sh
  • ./shutdown.sh
If you get permission denied error when running these scripts, you need to grant execute permission to the current user using the following command:

chmod u+x shutdown.sh


5. Configure access to Tomcat Web Application Manager

The Tomcat Web Application Manager allows us to deploy and manage Java web applications. It can be accessed by clicking the Manager App button on the localhost page. You will be asked for username and password:

sign in Tomcat 9 manager app

But we have not configured any users yet, right? So click Cancel button. You will see 401 Unauthorized error page as shown below:

unauthorized error Tomcat 9

This page shows the instructions about how to add a user in order to get access to the Tomcat web application manager. Change the current directory to conf and edit the tomcat-users.xml file using the following commands:

cd ../conf

open -a TextEdit tomcat-users.xml

open tomcat users xml file

This will open the TextEdit program to edit the tomcat-users.xml file. Remove the XML comments around <user> tags and keep only one username admin with your own password, as shown below:

edit tomcat users xml file

Close the program to save the change. Then stop and start the server, and you will be able to access the Tomcat Web Application Manager using the specified username and password:

tomcat web application manager

You can use this Tomcat Web Application Manager to deploy and manage Java applications running on the server. Check this article to learn about Java applications deployment on Tomcat. Watch the following video to see how to setup Tomcat 9 on macOS in action:

 

Other Tomcat Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment