I just installed memcached on my Mac OS X 10.6.8. It installed perfectly and when I type in memcached in Terminal I get this:

failed to listen on TCP port 11211 tcp
listen: Address already in use

And I have a script in my localhost that contains this:

$memcache = new Memcache();

But I get an error thrown saying Fatal error: Class 'Memcache' not found.

How can I get memcached to work, is it because the port 11211 is not listened to which probably doesn't make memcached work?

  • Don't go on chat to 'bump' up 5 minute old questions, things don't work that way, it'll just annoy other users who won't want to help you.
    – Chopper3
    Jul 2, 2011 at 12:47
  • I apologise for that.
    – MacMac
    Jul 2, 2011 at 16:03

5 Answers 5


Your first error is probably because memcached is already running. If you run ps -e | grep memcache | grep -v grep you'll probably see it. The output of netstat -a -p tcp | grep LISTEN will show you all the listening services too, which may help.

The second issue is probably because you don't have a memcache extension installed for your version of PHP (from the error I'm assuming you're using PHP). You probably want http://pecl.php.net/package/memcache to solve that.


Memcache could already be running. I had a crashed version of memcache running and got this problem.

I found this helpful:

netstat -l --protocol=tcpip --program

Once I had the pid I killed memcache

I then edited the config

vi /etc/sysconfig/memcached

I added


I also ran into the first error you reported:

failed to listen on TCP port 11211 tcp
listen: Address already in use

In my configuration I found the error was caused by multiple -l arguments to the same address. On Ubuntu my /etc/memcached.conf file contained:

-l localhost

memcached was able to successfully bind to the first address, but because duplicates localhost, memcached gave the Address already in use error when it tried to bind to the second address.

If you're running into this error and can't find an existing process binding to your port, double-check your memcached configuration. If you're listening for connections on multiple addresses, ensure those addresses don't represent the same address. Such a setup could cause this error.

  • Welcome to the community, please note that the question has been correctly answered before, and there is nothing I can find in common between what you have posted and what the OP's issue was, depending on the given answer. Please post technical answers, and avoid answers with no proof. BTW, your answer is not correct, so you can either remove it or edit it before anyone downvotes you. Wish you luck, and success. ;)
    – user356895
    Mar 24, 2017 at 18:52
  • Thank you for the clarification. I've expanded my answer to clarify that it address the OP's first question. I disagree that my answer is incorrect—there are multiple reasons memcached could produce an error that the address is in use. Having another instance of memcached running, as the accepted answer states, it most likely. However, I felt it might be helpful to people attempting to track down this problem to know this erro can occur without an existing instance running, and that starting an instance of memcached can produce this error.
    – Alex Clay
    Mar 26, 2017 at 0:28
  • As far as I could get you, you are trying to say one of either should be used and not both. So you can easily say: "remove one of duplicates if you're using both 127.1 and localhost at the same time." But by default, in memcached.conf, there is only -l No duplicate. On the other hand, this is not the -l option, it's just used for listening to the IP address which is 127.1 by default. Please correct your answer and provide more technical reasons. Good luck mate ;)
    – user356895
    Mar 26, 2017 at 6:29
  • BTW, you have a typo, that is memcached and not memcachd. Correct it please.
    – user356895
    Mar 26, 2017 at 6:29

I know this is an old question, but it was top of Google for me and I had a very different issue.

I had disabled ipv6 on an EC2 Amazon Linux 2 (Beanstalk) box. The standard configuration for memcached when installed from amazon-linux-extras is to require ipv6 localhost as one of the addresses to listen to.

I simply replaced the whole OPTIONS= line with

sed -i -E "s/OPTIONS=.+//g" /etc/sysconfig/memcached
echo 'OPTIONS="-l"' >> /etc/sysconfig/memcached

In my case it was because memcached was already running. Try:

$ ps aux | grep memcache | grep -v grep 

jill.doe     93302   0.0  0.0 408916512   1888   ??  Ss   11:39am   0:00.04 memcached

You need the PID in order to kill the process:

$ kill 93302

This should at least solve the failed to listen on TCP port 11211 tcp issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .