Installing Tomcat on macOS 10.14 Mojave

The Servlet 4.0 specification is out and Tomcat 9.0.x does support it. Time to dive into Tomcat 9. [updated on Sep.2.2018]

Prerequisite: Java

Since OS X 10.7 Java is not (pre-)installed anymore, let’s fix that first. As I’m writing this, Java 11.0.1 is the latest version and AdoptOpenJDK is one of the best places to find Prebuilt OpenJDK Binaries. Easy to follow details about how to install OpenJDK are available here. Anyway, after opening the Terminal app again,

hopefully shows something like this:

Whatever you do, when opening Terminal and running ‘java -version’, you should see something like this, with a version of at least 1.8.x I.e. Tomcat 9.x requires Java 8 or later.

sudo
sudo is a program for Unix-like operating systems, allowing you to run programs with the security privileges of another user (normally the superuser, or root). Since we are creating directories, outside of your home folder, administrator right are required. I.e., when executing sudo you will be asked to enter your password; and your Mac User account needs to be an ‘Admin’ account.

JAVA_HOME is an important environment variable, not just for Tomcat, and it’s important to get it right. Here is a trick that allows me to keep the environment variable current, even after a Java Update was installed. In ~/.bash_profile, I set the variable like so:

Installing Tomcat

Here are the easy to follow steps to get it up and running on your Mac

  1. Download a binary distribution of the core module: apache-tomcat-9.0.13 from here. I picked the tar.gz in Binary Distributions / Core section.
  2. Opening/unarchiving the archive will create a new folder structure in your Downloads folder: (btw, this free Unarchiver app is perfect for all kinds of compressed files and superior to the built-in Archive Utility.app)
    ~/Downloads/apache-tomcat-9.0.13
  3. Open to Terminal app to move the unarchived distribution to /usr/local
    sudo mkdir -p /usr/local
    sudo mv ~/Downloads/apache-tomcat-9.0.13 /usr/local
  4. To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat (after removing the old link, you might have from installing a previous version):
    sudo rm -f /Library/Tomcat
    sudo ln -s /usr/local/apache-tomcat-9.0.13 /Library/Tomcat
  5. Change ownership of the /Library/Tomcat folder hierarchy:
    sudo chown -R <your_username> /Library/Tomcat
  6. Make all scripts executable:
    sudo chmod +x /Library/Tomcat/bin/*.sh

Tomcat 9.x

Instead of using the start and stop scripts, like so:
$ /Library/Tomcat/bin/startup.sh
$ /Library/Tomcat/bin/shutdown.sh

 

you may also want to check out Activata’s Tomcat Controller, or here  a tiny freeware app, providing a UI to quickly start/stop Tomcat. It may not say so, but Tomcat Controller works on macOS 10.14 just fine.

 

Finally, after your started Tomcat, open your Mac’s Web browser and take a look at the default page: http://localhost:8080

Share this post:

42 Replies to “Installing Tomcat on macOS 10.14 Mojave”

  1. Nice tuto, one short question: I run a macOS Server 5.2 on 10.11.x and plan to install alfresco community installer on it, beside of Port Changes, any recommendations ? Should work side by side or may apache issues ?

  2. Thanks Wolf. This is exactly what I needed at exactly the right time.
    I will let you know how it goes and any thing I might add to your instructions set.
    I doubt that I’ll need to do that tho.

    Best Regards,

    Mike

  3. worked like a charm

  4. Thank you, was exactly what I needed! Nice tip with the “Activata’s Tomcat Controller”.

  5. thanks. worked like a charm. I wish life was always this easy. 🙂

  6. This was ninja stuff, worked like a charm on my mac… thanks a lot…

  7. David Hernandez says: Reply

    Nice Job, it’s a excellent information. you help me to install Tomcat yin my computer, Thanks.. 🙂

  8. Thanks a lot, Wolf. I had some issues with new mac os sierra and now it works like a magic.

  9. Saradhi Pinapati says: Reply

    Very Nice Tutorial. Saved my day. It’s working well.

  10. username / password for app manager?

  11. Thanks you, it work OSX sierra 😀

  12. Thank you.

  13. Excellent tutorial. Thanks!

  14. thanks for sharing this one

  15. Awesome post, worked like a charm. Thanks Wolf!

  16. GREAT how-to step-by-step just, add “-L” to the chown command to follow symlinks and the user can handle the startup scripts

    regards!

  17. Thank you Wolf – it saved the day

  18. MONOJIT DATTA says: Reply

    Nice and short, served my purpose, Thanks!

  19. Work like a charm!

  20. THANK YOU SO MUCH!!!!

  21. Thanks for this post.
    Did anyone notice the error message in /logs/catalina.out ??
    1.The APR based Apache Tomcat Native library … was not found on the java.library.path
    2The XML schema [ lots of files ] could not be found. This is very likely to break XML validation if XML validation is enabled.
    3.Failed to start component …[ all the subdirectories]

  22. Great tutorial, thank you very much! I just moved Tomcat into my Documents folder for now so I could mess with it there without going through terminal for certain configs (makes it easier with Brackets as a text editor).

  23. Simple and effective, thanks mate. Working on High Sierra as well.

  24. Ari Tjahjawandita says: Reply

    I am a newbie. I need to run a web app that needs Apache Tomcat. I have tried XAMPP before. Is it possible to install Tomcat inside XAMPP, instead of inside macOS web server? Thanks

  25. very nice guide, thanks folks

  26. Thanks very much for the excellent guide to install Tomcat on Mac, its very easy to follow and effective.

  27. Thank you so much!! It’s really helping 😀

  28. Thank you!

  29. Great post, thank you.

  30. Thanks a lot! Simple and smooth.

  31. A very short and easy guide. Thanks

  32. Many thanks, I was having difficulties getting Tomcat to run on OSX 10.13, until I found this!

  33. Thank you, from Costa Rica

  34. Great instructions. Worked first time. Having awful problems with my site after Mojave update so hoping this is the first step to getting it all back on line. Its not up yet!!

    Cheers,

    Lee.

  35. With jdk-11.0.1, paths have changed, log shows:
    /Library/Tomcat/bin/catalina.sh: line 464: /System/Library/Frameworks/JavaVM.framework/Versions/Current/bin/java: No such file or directory.
    I’ve located java under:
    /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands

    I’m stumped as to how to change it, in setclasspath.sh? Not the easiest script to edit.

    Just installed a new MacPro, running Mojave, so it’s a clean install

    1. Same problem. startup.sh failed (localhost:8080 not found). But starting Tomcat with ./Catalina.sh run did start Tomcat. Then there is the question of how to start Tomcat with a launchd *.plist LaunchDaemon.

      1. Make sure your JAVA_HOME env variable it set correctly. I.e. open terminal and enter ‘echo $JAVA_HOME’
        For openJDK for instance something like this would be correct:
        /Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home

        why not put this into you ~/.bash_profile

        export JAVA_HOME=$(/usr/libexec/java_home)

    2. Make sure your JAVA_HOME env variable it set correctly. I.e. open terminal and enter ‘echo $JAVA_HOME’
      For openJDK for instance something like this would be correct:
      /Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home

      why not put this into you ~/.bash_profile

      export JAVA_HOME=$(/usr/libexec/java_home)

      1. There were a number of issues (mostly updating commons*.jar files), but this helped in my .bash_profile:
        JAVA_HOME=$(/usr/libexec/java_home) PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME
        Thanks for the reply!
        Now if I can just get the launchd tomcat*.plist to load on reboot….

  36. Great instructions, thanks! Also works nicely on High Sierra.

    Has anyone managed to create a launchd plist item for Tomcat 9?

  37. Haven’t thoroughly tested it, but it runs so far..: buyer beware …

    Create file:
    /Library/Tomcat/bin/tomcat-launchd.sh

    #!/bin/bash
    # Shell script to launch a process that doesn’t quit after launching the JVM
    # This is required to interact with launchd correctly.

    function shutdown( )
    {
    $CATALINA_HOME/bin/catalina.sh stop
    }

    export CATALINA_HOME=/Library/Tomcat
    export TOMCAT_JVM_PID=/tmp/$$

    . $CATALINA_HOME/bin/catalina.sh start

    # Wait here until we receive a signal that tells Tomcat to stop..
    trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP

    wait cat $TOMCAT_JVM_PID

    —————-
    Create the file: /Library/LaunchDaemons/org.apache.tomcat.plist

    Disabled

    EnvironmentVariables

    CATALINA_HOME/Library/Tomcat
    JAVA_HOME/System/Library/Frameworks/JavaVM.framework/Versions/Current

    Labelorg.apache.tomcat
    OnDemand
    ProgramArguments

    /Library/Tomcat/bin/tomcat-launchd.sh

    RunAtLoad
    ServiceDescriptionApache Tomcat
    StandardErrorPath/Library/Tomcat/logs/launchd.stderr
    StandardOutPath/Library/Tomcat/logs/launchd.stdout
    UserNamesetspxadm

  38. Very Impressive Post… Thank You for share…

Leave a Reply

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