How To Install Tomcat In MacOS

Apache tomcat is a widely used web server. It can be installed an run in numerous operating system like Windows, Linux and MacOS. This article will tell you how to install it in MacOS step by step. But before install it, you should enable root user in MacOS following article How To Enable Root User Or Change Root Password In MacOS

1. Install Apache Tomcat In MacOS Steps.

  1. First make sure you have installed jdk in MacOS, run java -version in terminal to get the installed version. If you do not have installed jdk, you need to download and install one.
    sh-3.2# java -version
    java version "1.8.0_172"
    Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
  2. Download tomcat install package from page. You can select zip file or tar.gz file.
  3. After download, unzip the compress file to a local directory.
  4. Run cd go to the unzip file directory.
  5. Then run below command to make the .sh file executable.

    sh-3.2# cd /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8

    sh-3.2# sudo chmod +x ./bin/*.sh

  6. Now all the .sh file in tomcat bin directory is executable, you can run ls -al command to see that.
  7. now run ./bin/ to start tomcat. When you see below message, it means tomcat has been started successfully.
    sh-3.2# ./bin/ 
    Using CATALINA_BASE:   /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8
    Using CATALINA_HOME:   /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8
    Using CATALINA_TMPDIR: /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8/temp
    Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
    Using CLASSPATH:       /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8/bin/bootstrap.jar:/Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8/bin/tomcat-juli.jar
    Tomcat started.
  8. Now open a web browser, input http://localhost:8080/ in the url address input box. Click enter then you can see below web page.
    tomcat start successful
  9. To stop tomcat, you can run ./bin/ command in terminal.

2. How To Change Tomcat Default Listening Port Number.

Tomcat default listen on port 8080. When you meet error during startup tomcat, the reason maybe that port number has been used by other progress. So you need to change the port number to what you need. Below is the steps to change tomcat server http port number.

  1. Open tomcat-install-directory/conf/server.xml file in a file editor. In my environment, the server.xml located at /Users/zhaosong/Documents/WorkSpace/tool/apache-tomcat-9.0.8/conf/server.xml.
    tomcat server listen port number configure xml file
  2. Find below connector configuration in server.xml file. And change the port number from 8080 to what you want  such as 8089
    <Connector port="8089" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
  3. Save above settings and start tomcat again, now you can access tomcat from new url http://localhost:8089/.

8 thoughts on “How To Install Tomcat In MacOS”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.