HowTo install memcached from sources on Linux

This article will explain how you can install the latest memcached daemon (including the libevent library) on a linux system. The only prerequisite for memcached is libevent so we will have to install this first.

Note: the output of the commands in this article are taken from a Debian Etch system. They should work on any recent linux distribution, but depending from your version you might need to make some changes. The versions of memcached and libevent used in this article are the latest stable one existing at the time this was written. Check the download pages bellow, and if newer versions exists you will probably want to use them.

Install Libevent 1.3e

I will assume that you don’t have libevent installed already on your system. Your system might already have libevent installed, but normally you will have a very old version (for ex. on debian etch the packaged libevent is 1.1a that was released in 2005); in this case you will want to remove the system package first (for ex. on debian run: aptitude purge libevent1). If you have a recent version packaged by your linux distribution you should keep it and move on the next step to install directly memcached.

Download, and install the latest version of libevent (check for the latest version, and change if needed the versions bellow):

cd /usr/local/src
wget http://monkey.org/~provos/libevent-1.3e.tar.gz
cd libevent-1.3e
./configure
make
make install

This will install by default the libraries under /usr/local/lib/. If you want it in another place you can do that by passing to configure a different prefix.

Depending on your system you might have already /usr/local/lib included in your ld configuration. If this is not the case (like on my test debian box) you can add it inside /etc/ld.so.conf, or as a nice debian “thing” you can just create a new file inside /etc/ld.so.conf.d/ like:

vim /etc/ld.so.conf.d/libevent.conf
##add a line containing:
/usr/local/lib/

Regardless of your choice you should run ldconfig to complete this step:

ldconfig -v

(and check the output to be sure that the /usr/local/lib has been properly included).

Install Memcached 1.2.4

After we have libevent properly installed on the system we can proceed and install memcached. Download the latest stable version and install it using the following steps:

cd /usr/local/src
wget http://danga.com/memcached/dist/memcached-1.2.4.tar.gz
tar zxvf memcached-1.2.4.tar.gz
cd memcached-1.2.4
./configure
make
make install

The memcached binary will be also installed by default under /usr/local/bin/. You can start the daemon by simply running: /usr/local/bin/memcached. The basic memcached options are: memcached -d [-m memory_in_megabytes [-l listen_ip_address [-p listen_port]]] For ex:

memcached -d -m 256 -u nobody -p 11211 -l 192.168.0.1

will be used to run a memcached daemon bind on 192.168.0.1 on the default port 11211 using max 256MB memory.

I hope you found this article useful. If you prefer to install memcached from packages you might find these older posts useful: “Memcached 1.2.2 on Debian Etch”, and “Memcached 1.2.2 on Centos/RHEL”. if you are looking how to build the php memcache module you can find more information about that on my older post…

comments powered by Disqus