Installing Tomcat 8 on OS X Yosemite

Installing Tomcat 8 on OS X Yosemite is actually quite easy. One can do it with the help of Homebrew or MacPorts, but I prefer to do it “by hand”. All you have to do is to follow the steps below.

First, head over to the Apache Tomcat download page and download the core binary distribution in the tar.gz format. Once downloaded, the rest of the work will be done within the Terminal. Start by extracting the downloaded archive.


cd ~/Downloads
tar -zxvf apache-tomcat-8.0.20.tar.gz

The file name of course depends on the particular version that you downloaded. Once extracted, we will move the folder into the /usr/local directory, first ensuring that it exists (even though it should).


sudo mkdir -p /usr/local
sudo mv ~/Downloads/apache-tomcat-8.0.20 /usr/local

Now we will remove any Tomcat installation that could theoretically already be at /Library/Tomcat and create a new symbolic link to the installation directory. By creating a symbolic link, the path to our Tomcat 8 installation is more convenient and can easily be updated if a new version of Tomcat is installed. Thus, we would not have to update configurations in applications that may be using Tomcat, such as an IDE.


sudo rm -f /Library/Tomcat
sudo ln -s /usr/local/apache-tomcat-8.0.20 /Library/Tomcat

Now we will just set the owner of the directory and files recursively, and make sure that the scripts are executable.


sudo chown -R /Library/Tomcat
sudo chmod +x /Library/Tomcat/bin/*.sh

At this point, Tomcat 8 should successfully be installed on your Mac. To start it, simply use the following commands.


cd /Library/Tomcat/bin
./catalina.sh start

Similarly, to stop it, use the following commands.


cd /Library/Tomcat/bin
./catalina.sh stop

That is it! You should now be able to access Apache Tomcat’s welcome page on http://localhost:8080. If you wish to make starting and stopping Tomcat 8 a little simpler, then you could create a few convenience commands on OS X.

7 Comments

  1. Jon said:

    sudo chown -R /Library/Tomcat
    I had to explicitly put specify root to make it work. sudo chown -R root /Library/Tomcat

    sudo chmod +x /Library/Tomcat/bin/*.sh
    I couldn’t make it work. It throws error:
    chown: +x: illegal user name

    I am working on MAC OS X El Capitan and using apache-tomcat-8.0.26

    August 31, 2015
    Reply
    • Bo Andersen said:

      Ah, the steps in the article worked for me on Yosemite. Thank you for sharing this!

      September 3, 2015
      Reply
      • Morgan Lemke said:

        This worked perfectly fine for me in El Capitan.

        December 14, 2015
        Reply
  2. Angela said:

    Thanks a lot!

    September 23, 2015
    Reply
    • Bo Andersen said:

      You are welcome – happy to help! :-)

      September 23, 2015
      Reply
  3. Richard said:

    Hi Bo, this page is really quite helpful. However, the change of ownership command can’t ever work, even on Yosemite, which I am also using.

    Richards-MacBook-Pro:Tomcat rwilliams$ sw_vers -productVersion
    10.10.5
    Richards-MacBook-Pro:Tomcat rwilliams$ pwd
    /Library/Tomcat
    Richards-MacBook-Pro:Tomcat rwilliams$ sudo chown -R /Library/Tomcat
    usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...
           chown [-fhv] [-R [-H | -L | -P]] :group file ...
    

    The other command works, but because the default in “chmod” is to apply the change to all levels of User, Group, and World (“ugw”). I’m searching forums because I want to know what the correct change is, but I’m experienced enough to be cautious of this being the appropriate choices, since giving Execute privilege to everyone on the Catalina shell scripts is probably a huge security no-no.

    For the super-newbies, here’s some background explanation about why we see this issue and have to try and solve it:

    When you unpack the gz.zip archive, the distribution has the development project’s users names/groups on the files. Your systems won’t have those same usernames, so you have to change the ownership. Also, in your system the Groups will likely be different. So you find yourself using “sudo” to get Tomcat to Startup and Shutdown … but you don’t really want to do that because, maybe, your use-case won’t be allowed to use sudo.

    So, if you want to start Tomcat without using Sudo, you have to change these permissions, and if you don’t it’ll say touch: /Library/Tomcat/logs/catalina.out: Permission denied.

    That’s because when a user tries just “./startup.sh”, the script tries to run as whatever user you happen to be logged-in as. That user does not have some critical permissions: For instance, they don’t have +w on /Library/Tomcat/logs, so the Catalina startup.sh can’t perform a “touch” on the /…/logs/catalina.out file. Likewise, without the +x (Execute) permissions, starting Tomcat without Sudo will throw touch: /Library/Tomcat/logs/catalina.out: Permission denied.

    The Startup only tries to “touch” (create) that file if the file does not already exist, because the rest of the Tomcat server behaviors will try to append to the log file … and if the file is missing those log-write commands will fail with “file not found” I/O errors.

    So I, like many other readers, don’t know what the correct ownership/permission target – User, or Group, needs to be given those permission? Yes, I can guess, and I can give huge-permissions to the whole world and get it going … but that’s not the point: What we’re all trying to figure is, what is the correct level of permissions and to whom?

    … and so the search for the specific (and correct) answer goes on :)

    October 26, 2015
    Reply
    • Bo Andersen said:

      Hello Richard,

      Thank you very, very much for your detailed comment! Actually, those commands worked perfectly well on my MacBook running OS X Yosemite at the time of the writing. Either way, you are right about the permissions. The reason why I am so “generous” with the permissions is two-fold; firstly, given that this article is related to OS X, the target audience is developers needing to install this on their development machines. In theory, this may not be the case, and I might have to make this more clear in the article. Also, I am by no means a UNIX guru, so this was just what worked for me.

      My particular setup has always been shielded off from the Internet, so I haven’t really thought much about this.

      Thanks a lot for the feedback!

      October 26, 2015
      Reply

Leave a Reply

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