Installing Memcached

Sep 03, 2007

Memcached is an alternative to database storage that is often useful for session storage and caching. It was developed by the guys at live journal to help them maintain their unwieldy sessions. Since then it's gained a lot of popularity among the PHP and Rails folk because it removes some of the burden on the typical database bottle neck, and allows things like session to be maintained across a cluster of servers.

First things first, you're going to need to download and make the source for libevent, which memcached has a dependency on:

wget http://www.monkey.org/~provos/libevent-1.3d.tar.gz

tar zxf libevent-1.3d.tar.gz

cd libevent-1.3d

./configure --prefix=/usr/local

make; sudo make install; make clean;

cd ..


Once that is done, you're ready to get onto the setup and install of memcached itself:

wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz

tar zxf memcached-1.2.2.tar.gz

cd memcached-1.2.2

./configure --with-libevent=/usr/local/lib --prefix=/usr/local

make; sudo make install; make clean;

sudo /sbin/ldconfig /usr/local/lib

cd ..


And then finally, the ruby client interface:

sudo gem install memcache-client -y


Once that is installed, moving over your session store to use memcached is a breeze, simply change the setting in your environment.rb file to:

config.action_controller.session_store = :mem_cache_store


Hi, I'm Glenn! 👋 I'm currently Director of Product @ HashiCorp, and we're hiring! If you'd like to come and work with me and help make Terraform Cloud even more amazing we have multiple positions opening in Product ManagementDesign, and Engineering & Engineering Management across a range of levels (i.e., junior through to senior). Please send in an application ASAP so we can get in touch.