Memcached: How do you install memcached? (CentOS 64 bit, Linux, Redhat, Fedora)

[updated 5/16/2010]

Memcached is a very popular open source object caching server. It was developed to speed up by Danga Interactive.  We use memcached for a lot of our sites.  We use it for different purposes but one main purpose is to cache query results so we don’t have to keep hitting database.  As most of the people who work with databases know it is costly to keep hitting database for same information over and over.

When you run the Memcached daemon, it runs and listens on a specific port. One of the things Memcached does lack is security. Memcached will let anybody who can make a connection to its port have full access to all objects. So you would have to run a firewall to block unauthorized access. It is usually wise to do put firewall on it even if you trust everybody on the same network since accidents do happen. That said, let’s get memcached installed!

Let’s get libevent which is required by Memcached:

tar zxpfv libevent*
cd libevent*
make install

Now let’s download the newest Memcached source (at time of update to this post 1.4.5 was the latest)

tar zxpfv memcached*
cd memcached*
make install

Let’s add Memcached user to run daemon as since we don’t need it to run as root privileges.

adduser memcached

We will start the server to use 48 megs of ram (-m 48), listen on ip (-l and run on port 11211 (-p 11211) as user memcached (-u memcached)

./memcached -u memcached -d -m 48 -l -p 11211

If you get the following error (which you will get if you are doing this under CentOS 64 bit):

./memcached: error while loading shared libraries: cannot open shared object file: No such file or directory

You can fix this by simply doing this:

ln -s /usr/local/lib/ /lib64/

That is all there is to it. You can see if daemon is running by telneting to the port.

DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

27 thoughts on “Memcached: How do you install memcached? (CentOS 64 bit, Linux, Redhat, Fedora)

  1. CrazyToon Post author

    Most of the times, using package managers to install won’t get you the latest version. With yum, it tried to download/install 1.2.3-7 on my fedora install. Thanks for the tip though. I am sure for people who don’t care, it would work out just fine.

  2. Gabriel

    Got the error: ./memcached: error while loading shared libraries: cannot open shared object file: No such file or directory

    The solution for me: libevent files where installed at /usr/local/lib, I had to move them to /usr/lib and check if symbolic links were correct.

  3. KEMBL

    On CentOs 5.1 libevent may be installed like:

    yum install libevent

    but ‘yum install memcached’ still cant.

    After this, you can download last version memcached

    and go on as described abow, in some cases may apper this error

    checking build system type… Invalid configuration `x86_64-unknown-linux-‘: machine `x86_64-unknown-linux’ not recognized
    configure: error: /bin/sh ./config.sub x86_64-unknown-linux- failed

    for now, I duno how to deal against it, but will dig

  4. Shannon Haworth

    I Just finished installing on CentOS 5.1. Downloaded and built both libevent and memcached as instructed.

    However memcached could not load the shared library

    Next I tried a “make clean” followed by
    “./configure –with-libeven=/usr/local/lib” however I received the same error as before.

    I was able to solve the problem by creating a symlink between /usr/local/lib/ and /usr/lib “ln -s /usr/local/lib/ /usr/lib”

    Hopefully this will help someone else.

  5. Shannon Haworth

    Update to my last comment:

    –with-libeven should have been –with-libevent

    Also, I did remember to run make install after I ran configure.


  6. Pingback: Installing memcache on linux and add to PHP | JumpJava

  7. Pingback: » Installing memcached On CentOS

  8. Raul Macias

    This is a great tutorial; thanks for sharing it.

    I have a CentOS server and followed your instructions to install MemCached on it.

    My question is: how can I change the settings on CentOS to make MemCached accesible to other machines on my network?

    I’m running a windows console application that uses Enyim.Caching and it seems that it can’t get to the Memcached instance.

    How can I tell from a Windows machine if Memcached is up and running?

    Thanks in advance.


  9. Sunny Walia Post author


    You can telnet to the instance. For example if you were running memcached on server with ip of on port 11211, on windows you would goto command prompt and type: telnet 11211

    if that doesn’t work and you know memcache is running and listening on that port, you may have firewall turned on. You can either allow that port or turn off the firewall to temporarily test. I suggest you figure out how to allow the port instead of turn off firewall completely.

  10. Raul Macias


    in the CentOS server, I ran this command to find out it’s IP address
    # ifconfig
    now I know the machine is running with this address:

    then I ran this
    # memcached -l -p 11211 -d -u nobody

    after that I ran this command to see if memcached is up and running:
    # netstat -ant | grep LIST
    at the top, I see this
    tcp 0 0* LISTEN

    I assume that means memcached is running on that ip address and port

    now from another machine (MacOS), I open a terminal window and type the following:
    $ telnet
    then I get this: nodename nor servername provided, or not known

    does that mean the port is blocked or not opened in the CentOS server?

    thanks for your help


  11. Raul Macias

    my mistake, when I try doing the telnet command like this
    $ telnet 11211
    I get
    telnet: connect to address Connection refused
    telnet: Unable to connect to remote host

  12. larry

    Can’t compile memcached 1.4.5 on RHEL 5.5
    ./configure –with-libevent=/usr/lib64/
    still results in error that libevent needs to be installed.
    Installed libevent is libevent-1.4.13-1
    linking /usr/lib64/ to /lib64 or /usr/lib doesn’t help.
    Has anyone been able to compile memcache on RHEL 5.5?

  13. Pingback: Memchached - vBulletin SEO Forums

  14. film semi jepang

    Amazing blog! Do you have any suggestions for aspiring writers?
    I’m planning to start my own website soon but I’m a little lost on everything.
    Would you advise starting with a free platform like WordPress or go
    for a paid option? There are so many options out there that I’m totally confused ..

    Any recommendations? Cheers!

  15. phentermine

    I tilted myself that will where I’d been leaning just a bit away from the part, enough
    to kick advertising as hard as I could possibly.
    And remember it’s a must that the DJ is aware of their crowd in case of
    emergency – can’t be all fucked up (high & drunk) not paying attention and then on top of
    that can’t change your mood music cuz all you brought was the bang bang
    four on the floor. I really threw beers and booted the wall structure and swore seeing that loud after i
    could free of Beth experiencing me.

  16. Pingback: Answer for What is the best way to setup memcached on CentOS to work with Apache and PHP - Tech Magazine

  17. Pingback: What is the best way to setup memcached on CentOS to work with Apache and PHP [ANSWERED] - Tech ABC to XYZ

Leave a Reply

Your email address will not be published. Required fields are marked *