Installation on Mac OS X is quite a straightforward process if you have the right tools installed.
We will be using a package manager for Mac OS X that is really a must-have tool for any Mac user and even more important if you are a developer or a system engineer.
The package manager we will be using is Homebrew, the missing package manager for OS X
You will need to install Homebrew first if you don't have it, installation is straightforward and all instructions are explained in different languages for your comfort at http://brew.sh/.
Or you can simply use this one liner to install Homebrew on your Mac:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Update the Homebrew local repository:
brew update
Use Homebrew to install the memcached package:
brew install memcached
Memcached is not started by default after installation, if you manually want to start memcached use,
/usr/local/opt/memcached/bin/memcached
If you are planning to start memcached on boot every time, you will need to create a link:
ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
Then, you may want to start memcached immediately using
launchctl
:launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
We started by updating the local copy of the Homebrew repository from the Internet using the brew update, this ensures we are installing the latest version of any package we want to. Then we installed the latest version of memcached.
Homebrew does not start memcached automatically after installation nor during boot time, so we had to do this ourselves.
You can always start memcached manually in the foreground by using the memcached daemon executable. But if you want memcached to start on boot we created a symlink so that launchctl
picks it up on boot.
If you have configured your memcached daemon to start on boot as previously described, you might be wondering, where is the default configuration? Is it in the same place as Ubuntu? The answer is No!
Because the memcached service will be started by launchctl
, the configuration is controlled by it. You will find the configuration file at /usr/local/opt/memcached/homebrew.mxcl.memcached.plist
and it's basically an XML file.
See the following section in the file:
<array> <string>/usr/local/opt/memcached/bin/memcached</string> <string>-l</string> <string>localhost</string> </array>
As you may have discovered yourself, this represents a list of parameters passed to the memcached executable at runtime.
You can edit the localhost
field, as previously described in the Ubuntu configuration section, but if you want to configure the amount of memory that memcached can use, you will need to insert a couple of directives for that directly after the localhost directive:
<string>-m</string><string>256</string>
This configures memcached to use up to 256 MB of memory for its on-memory storage.
Another option if you are not a Homebrew user, is to use MacPorts (http://www.macports.org/), it works almost the same way and you can use the command port instead of brew.
Another interesting feature of brew, is that you can specify options to control the way memcached is built (compiled), so most of the time you don't really need to compile memcached from source on Mac OS X, instead, you use brew options for that. An example, is to enable SASL support to disable the plain ASCII protocol or to add SASL with password option, as stated in the brew info memcached
.
--enable-sasl Enable SASL support -- disables ASCII protocol! --enable-sasl-pwdb Enable SASL with memcached's own plain text password db support -- disables ASCII protocol!
So, for example, if you want to enable SASL support during installation, use the following:
brew install memcached --enable-sasl