How to install Memcached Server on Mac OS/Linux

Filed Under: Scripts

Memcached is an open source high performance distributed memory object caching system. It is one of the most widely used cache mechanism used by some of the biggest websites like WordPress.com and LiveJournal.com.

It is also used by VBulletin software, for faster performance, that is one of the best software for Forums. It’s easy to install and there are so many client programs available on the Internet in different languages.

Read: Memcached Java Client

Install Memcached on Mac OS

Memcached is a memory based caching mechanism and build using C language. To install memcached server on Mac OS or Linux we need C library. Here I am assuming that C library is already present in the system. If it’s not, then you can download C compiler and install it or install XCode that installs GCC compiler with it.

After that, you need to install the libevents library.

Steps are;


$ curl -OL https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz

$ tar -xvf libevent-2.1.8-stable.tar.gz 

$ cd libevent-2.1.8-stable

$ ./configure --prefix=/usr/local

$ make

$ sudo make install

Once libevents is installed then you can install memcached server.

Steps are;


$ curl -O https://memcached.org/files/memcached-1.5.0.tar.gz

$ tar -xvf memcached-1.5.0.tar.gz 

$ cd memcached-1.5.0

$ ./configure --prefix=/usr/local

$ make

$ sudo make install
Password:
$ 

install memcached server on mac os and linux

Now Memcached server is installed in your system. If the libevent library is not installed, configure command will give the following error.


$ ./configure --prefix=/usr/local
...
checking for libevent directory... configure: error: libevent is required.  You can get it from http://www.monkey.org/~provos/libevent/

      If it's already installed, specify its path using --with-libevent=/dir/

pankaj:memcached-1.5.0 pankaj$ 

Memcached Server on Different Port

By default, memcached server runs on TCP port 11211 and listens on UDP port 11211 and you can run multiple instances of memcached server from one installation.


$memcached -d

Above command will start the Memcached server on TCP port 11211 and listens on UDP port 11211 as a daemon process.


$memcached -p 11111 -U 11111 -d

Above command will start the Memcached server on TCP port 11111 and listens on UDP port 11111 as a daemon process.

Test Memcached Server using Telnet

Next step is to use memcached telnet commands to test that it’s working fine.

In some of the Linux systems, you also need to add the libevent library location in the path.

If you get following error in starting memcached server:

./memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

Then add following configuration in user profile (for example, .bash_profile or .profile)

$export LD_LIBRARY_PATH= /usr/local/lib

Or, provide it’s path using --with-libevent option in configure command.

I have used the above steps to install Memcached server in Linux and Mac OS systems. If you face any issues, let me know. I will try to resolve them.

Happy Caching…

Further Reading: Install Memcached on CentOS and PHP integration

References:

Comments

  1. N says:

    Do you know how to install memcache on mac with SASL support? can you please help?

  2. Akshay Lokur says:

    I was looking for only this information. Really helped.
    Thanks Pankaj 🙂

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages