Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Created April 26, 2016 13:27
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save tomysmile/ba6c0ba4488ea51e6423d492985a7953 to your computer and use it in GitHub Desktop.
Save tomysmile/ba6c0ba4488ea51e6423d492985a7953 to your computer and use it in GitHub Desktop.
Installing memcached on Mac with Homebrew and Lunchy

Installing memcached on Mac with Homebrew and Lunchy

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.

Step 1 — Install Homebrew

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 doctor

Step 2 — Install memcached

Installing anything with Homebrew is a breeze. All you need is

$ brew install memcached

When 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.

Step 3 — Install Lunchy

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 lunchy

Step 4 — Start/Stop memcached

Now 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 memcached

Lines 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 the Installation

Verify that you have successfully installed Memcached.

$ memcached -V

Using the Memcached Telnet Interface You can connect to the Memcached server with Telnet.

telnet localhost 11211

To test if everything is working correctly, set a cache item.

set foo 0 900 5
hello

To retrieve the cache item.

get foo

To exit the Telnet session.

quit

For more information on using Memcached Telnet commands.

Invalidate All Cache Items

To flush the contents of your Memcached server. Useful in a development environment.

echo 'flush_all' | nc localhost 11211

That's it.

@ecrofeg
Copy link

ecrofeg commented Jul 12, 2019

Thanks!

@McAlyster
Copy link

Thanx !

@novoydarskiy
Copy link

Thank you!

@cy6581
Copy link

cy6581 commented Aug 19, 2020

Nice works perfectly!
Alternatively, to start and stop memcached you can also use:
brew services start memcached
brew services stop memcached

@TorvaldsDB
Copy link

Nice works perfectly!
Alternatively, to start and stop memcached you can also use:
brew services start memcached
brew services stop memcached

thank you! you helped me as well.

@gokulprathin8
Copy link

Thanks!

@Aashishkumar123
Copy link

While running memcached server on mac i'm getting this Error: No such file or directory @ rb_sysopen - /Users/jayant/Library/LaunchAgents/homebrew.mxcl.memcached.plist
I tired brew services restart memcached command to start the memcached server on mac but get this exception , please anyone have any idea why i am getting this error please help

@samirpatel-slingshot
Copy link

On mac 12.6.1 the directory location is /opt/homebrew/Cellar/memcached/$version/homebrew.mxcl.memcached.plist

@dalelantowork
Copy link

$ brew install memcached
this broke my copy of php.... and it didnt work for me....
cp /usr/local/Cellar/memcached/$version/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/version/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/

says command not found

@mojgan-git
Copy link

mojgan-git commented Jun 12, 2023

hi experts, can anyone pls help me with this issue: (trying to install PHP memcached extension)

pecl install memcached --with-zlib-dir=/opt/homebrew/opt/zlib/

checking for pkg-config... /opt/homebrew/bin/pkg-config
checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=

to specify the prefix where ZLIB headers and library are located
ERROR: `/private/tmp/pear/temp/memcached/configure --with-php-config=/opt/homebrew/opt/php/bin/php-config --with-libmemcached-dir=no --with-zlib-dir=no --with-system-fastlz=no --enable-memcached-igbinary=no --enable-memcached-msgpack=no --enable-memcached-json=no --enable-memcached-protocol=no --enable-memcached-sasl=yes --enable-memcached-session=yes' failed

no matter what i get this error, if i add zlib dir or not.. any insight pls?

@mojgan-git
Copy link

actually just installed it by these following commands:
brew link zlib --force
tar -xvzf memcached-3.2.0.tgz
phpize
./configure --with-zlib-dir=/opt/homebrew/opt/zlib
make install

brew didn't help, i had to install it directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment