Installing memcached on OS X 10.5.4 Leopard
Posted on August 19th, 2008 in memcached |
I used the guide here to install Memcached on my Macbook Pro, but seeing how it was written over 3 years old I decided to write an updated version for installing on OSX Leopard. Here goes:
Beforehand: You need to install Xcode 3.0 Developer Tools. If you don’t have it installed it’s on the Leopard Install CD that came with your Mac. You also have to install the X11 windowing environment on the same disc.
- If you don’t have it already, download Macports:
http://www.macports.org/install.phpHere’s the Leopard universal binary direct link:
http://svn.macports.org/repository/macports/downloads/MacPorts-1.6.0/MacPorts-1.6.0-10.5-Leopard.dmg (416kb) - Macports will install itself to
/opt/local/binbut on my machine I didn’t have a PATH variable set there so if you type “port” in your terminal and don’t get anything either, continue following this step, else just continue on to the next one.Open up terminal and type:
nano .bash_profile (return key)
Find the first unused line and type:
PATH=$PATH:/opt/local/bin
To save your changes press
ctrl-o(return key) andctrl-xto quit.
Refresh your profile by typing:. .bash_profile
- To test that your Macports is working (and to update to the newest version):
sudo port -v selfupdate
- Install libevent. It’s a dependency of memcached:
sudo port install libevent
- Install memcached:
sudo port install memcached
- Set an environment variable to stop libevent using kqueue (should force it to use select, which is slower, but actually works). I have no idea what this does, just following the original guide, but it’s related to making memcached faster :
Open up terminal and type:
nano .bash_profile (return key)
Find the first unused line and type:
EVENT_NOKQUEUE=yes
To save your changes press
ctrl-o(return key) andctrl-xto quit.
Refresh your profile by typing:. .bash_profile
- Run memcached (this gives it 24MB of memory max, and puts it on port 11211 - note that specifying a hostname will not work on OS X):
memcached -d -m 24 -p 11211
- Telnet to your memcache to make sure it’s working:
telnet localhost 11211
If you see “Connected to localhost”, you’re connected.
Type
quitto close the connection and try reconnecting again to make sure you did step 6 properly.You’re done!
To stop memcached, type this in your console:
killall memcached
To start memcached in verbose mode (so it outputs what it’s doing) add -vv to the startup script.
Feel free to create a bash script to startup memcached with your right settings, mine looks like this:
#!/usr/bin/env bash memcached -d -m 24 -p 11211 echo "memcached started..."
Related links:
Installing memcached on OS X 10.4 Tiger
Installing Macports
Memcached homepage
Further reading:
Setup a Memcached-Enabled MAMP Sandbox Environment
Install ruby memcached on MacOSX
2 Responses
Thanks for this. I’ve reached step 8 and I can see memcached is running - now I just need to follow the Railscasts and get set-up with Cache_fu. After a year on mac, I hadn’t used Mac Ports before and I didn’t know if installing it over the top of my existing os software would cause any problems - and installing Memcached without Memcached looked a little tricky and all the tutorials seemed years out of date - but I seem to be there now.
I haven’t set up the bash script, though - sorry for the newbie question - how do I actually do that? By the sounds of it, Memcached isn’t configured to start up when I boot OS X, so the bash script looks like a must-have.
How are things going at KickApps? Are you on Git/GitHub, per chance?
Hi Neil, to create this script open up textedit (convert it to plaintext mode) and copy and past the script above and save it with no file extension. I put all my one-off scripts in a folder called scripts in the root of my drive.
From there you can run the script by going to that folder in terminal and typing ./memcached. I don’t run memcached on startup because when I’m not doing web dev I don’t want it running. (Currently, I have an Eclipse “external tool” script to turn it off an on, for use in a java environment.)
To run memcached on startup you have three options that I can think of:
1) You can make the script a finder executable file by renaming it with a .command extension. Then you can leave it on your desktop and just double click it when you want it to run or link the file in your startup menu items in system preferences (if you’re on a mac). This has the probably unwanted side effect of popping open a new terminal window.
2) You can make a small applescript app that will run that terminal command and link to that in your startup - my applescript knowledge is limited, but I know this is doable.
3) You can create an official startup item. It’s a little complex but probably the best option:
http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/StartupItems.html
http://www.macdevcenter.com/pub/a/mac/2003/10/21/startup.html
Kickapps is doing good. Lots of cool stuff coming down the pipeline.
GitHub looks really interesting. I’m signed up but have yet to contribute to anything yet.
Nice blog. I enjoyed the MyBlogLog video.
Cheers,
Mauvis