This is a quick guide for installing memcached on a Mac with Homebrew, and starting and stopping it with Lunchy. I hope this tutorial will get your memcached up and running in no time.
Installing Homebrew is super easy. Just paste this in your terminal —
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"You should also make sure your Homebrew is up-to-date. Use update and doctor commands to update and fix any issues it may have.
$ brew update
$ brew doctorInstalling anything with Homebrew is a breeze. All you need is
$ brew install memcachedWhen you installed memcached, it put a file named homebrew.mxcl.memcached.plist in /usr/local/Cellar/memcached/$version/; you copy that file into ~/Library/LaunchAgents and then tell launchd to start it with launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist.
If you were watching the console carefully during the brew install command, it should have said something about doing these exact steps. If you run brew info it’ll re-print this information, e.g. brew info memcached.
But why remember this long location to start memcached every time? Lunchy is a gem that simplifies the command line interface to launchctl. To install Lunchy, do
$ gem install lunchyNow we configure lunchy to start/stop memcached using simple lunchy commands.
$ mkdir ~/Library/LaunchAgents
$ cp /usr/local/Cellar/memcached/$version/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
$ lunchy start memcached
$ lunchy stop memcachedLines 1 and 2 copy the plist file to LaunchAgents. The lines 3 and 4 start and stop memcached. Since lunchy takes care of the long commands we talked about in Step 2, we don’t have to use the launchctl command to launch anymore.
Verify that you have successfully installed Memcached.
$ memcached -VUsing the Memcached Telnet Interface You can connect to the Memcached server with Telnet.
telnet localhost 11211To test if everything is working correctly, set a cache item.
set foo 0 900 5
helloTo retrieve the cache item.
get fooTo exit the Telnet session.
quitFor more information on using Memcached Telnet commands.
To flush the contents of your Memcached server. Useful in a development environment.
echo 'flush_all' | nc localhost 11211That's it.
Nice works perfectly!
Alternatively, to start and stop memcached you can also use:
brew services start memcachedbrew services stop memcached