Nginx for Mac OS X El Capitan in 2 Minutes

Nginx on Mac OS X El Capitan

Before we get started

If you are running an earlier version of Mac OS X, please refer to one of my earlier articles which outlines the process and provides scripts to automate it for you. Choose your version of Mac OS X below:

Snow Leopard (v. 10.6.x) – Nginx on Mac OS X Snow Leopard in 2 Minutes.
Lion (v. 10.7.x) – Nginx on Mac OS X Lion in 2 Minutes.
Mountain Lion (v. 10.8.x) – Nginx on Mac OS X Mountain Lion in 2 Minutes.
Mavericks (v. 10.9.x) – Nginx on Mac OS X Mavericks in 2 Minutes.
Yosemite (v. 10.10.x) – Nginx on Mac OS X Yosemite in 2 Minutes.

If you are not sure which version of Mac OS X you are running, open Terminal and type:
system_profiler SPSoftwareDataType and you will see something like this:

macbookpro:~ kevin$ system_profiler SPSoftwareDataType
System Software Overview:
System Version: OS X 10.11 (15A284)
Kernel Version: Darwin 15.0.0
Boot Volume: Macintosh HD
Boot Mode: Normal
Computer Name: macbookpro
User Name: Kevin Worthington (kevin)
Secure Virtual Memory: Enabled
Time since boot: 3:03

Note the System Version line. As you can see, I have 10.11 which is El Capitan.

You may use newer versions of Nginx and the prerequisite software, but whether you choose to do that, or you stick to the packages outlined in the above article, you will get a working Nginx web server on your Mac. Please note that the included build script should still work on earlier versions of Mac OS X if you don’t want to go the DIY (do it yourself) route.

This guide will show you how I compiled a basic version of Nginx 1.9.6 on Mac OS X 10.11 El Capitan. The “2 minute” compilation that I mention in the title of this article is when using the script that I provide below. For the DIY folks, I’m breaking down the steps. Variations in your Mac’s specs, and your copy and paste skills may increase the total time to over 2 minutes.

First, if you do not already have it installed, download and install Xcode from the Mac App Store.

Install PCRE
Nginx requires PCRE – Perl Compatible Regular Expressions to build, I used PCRE version 8.37. In a Terminal window, run:
sudo mkdir -p /usr/local/src
cd /usr/local/src
sudo curl -OL
sudo tar xvzf pcre-8.37.tar.gz
cd pcre-8.37
sudo ./configure --prefix=/usr/local

Note: if you get an error that looks like this:

configure: error: in `/usr/local/src/pcre-8.37':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

then do the following:
Make sure to have Xcode installed.
Open Xcode.
Click on the Xcode menu (next to the Apple menu in the top left) -> Preferences -> Downloads -> Components -> Click on Command Line Tools and click “Install”
Then go back to Terminal and type:
sudo xcode-select -switch /Applications/
Then re-run:
sudo ./configure --prefix=/usr/local

Note: if you get an error that looks like this:

checking whether the C compiler works... no
configure: error: in `/usr/local/src/pcre-8.37':
configure: error: C compiler cannot create executables
See `config.log' for more details

Then re-run:
xcode-select --install
This will prompt you to install Command Line Developer Tools. Go through the installer and then continue below.

If you didn’t get an error, or cleared the above errors out, continue here:
sudo make
sudo make install
cd ..

Install Nginx
(You should still be in /usr/local/src, if you followed along from above.)
sudo curl -OL
sudo tar xvzf nginx-1.9.6.tar.gz
cd nginx-1.9.6
sudo ./configure --prefix=/usr/local --with-cc-opt="-Wno-deprecated-declarations" --with-pcre=../pcre-8.37
sudo make
sudo make install

Start Nginx
Assuming that you have /usr/local in your $PATH (which nginx should say:/usr/local/sbin/nginx), you can simply run:
sudo nginx
Note: to add /usr/local to your $PATH variable, edit or create ~/.profile to include it. For reference, mine currently looks like this:
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/X11/bin:/opt/X11/bin" – I emphasized in bold type what you need to add to your PATH.
You can also temporarily add /usr/local/sbin to your path by running:
export PATH=/usr/local/sbin:$PATH

The 2 Minute way, using a shell script
All of the above instructions, in a nice little script. Save it to your Mac as, open a new Terminal window and run:
chmod a+x
sudo ./

It’s a pretty quick process to get Nginx installed nicely on your Mac, especially if you use the shell script. This provides a very basic install, but it should get you moving in the right direction. Your feedback is appreciated, so leave a comment below.

Tweet ThisTweet This