Howtodojo logo
  • Home 
  • About 
  • Certifications 
  • Sample Database 
  • Cheatsheet 
  • Glossary 
  • Blog 
  • Tags 
  1.   Blog
  1. Home
  2. Blog
  3. How To Install Memcached From Source on Ubuntu 18.04

How To Install Memcached From Source on Ubuntu 18.04

Share via
Howtodojo
Link copied to clipboard

In this tutorial we learn how to compile and install Memcached on Ubuntu 18.04. We will also compile latest version of libevent for Memcached.

On this page
Overview   Prerequisite   Install Tools and Dependencies   References   Summary  
How To Install Memcached From Source on Ubuntu 18.04

Overview  

This tutorial explain how to compile and install memcached from source on Ubuntu 18.04 (LTS) Bionic Beaver.

Memcached can be use for any caching usage but mostly used by dynamic web application to reduce database load.

We can also cache API calls and page rendering.

Memcached (pronounced: mem-cash-dee) is a free, high performance, distributed memory object caching system.

Why Memcached from source? Ubuntu already shipped with Memcached but not the latest version. The version shipped with Ubuntu 18.04 is memcached 1.5.6 while the latest stable of Memcached is 1.6.9.

Prerequisite  

This tutorial assumes we have a fresh install of Ubuntu 18.04. Any flavor of ubuntu will works but in this tutorial I use Ubuntu Server 18.04.

Install Tools and Dependencies  

Before we can compile memcached, we need to install tools to compile memcached and memcached dependencies.

We can use command below to install three packages needed so we can compile memcached on ubuntu 18.04.

sudo apt-get install gcc make libevent-dev libc6-dev --no-install-recommends
```bash

We use `--no-install-recommends` options so apt will only install package that we asked to install and its dependencies only.

You can see description of each package that we install below:

* **gcc** is GNU C compiler that will be used to compile memcached source code
* **make** is utility for directing compilation
* **libc6-dev** is GNU C library and header files
* **libevent-dev** is asynchronous event notification library development files

## Compile Memcached on Ubuntu 18.04 {#h-compile-memcached-on-ubuntu-18-04}

Now all tools installed we can start compiling Memcached on Ubuntu 18.04.

Download memcached source code from memcached website.

Get latest version of Memcached from [Memcached download page][2].

We can use the command below to download Memcached source code using `wget`:

```bash
wget -c http://www.memcached.org/files/memcached-1.6.9.tar.gz

To download using curl we can use command below.

curl http://www.memcached.org/files/memcached-1.6.9.tar.gz --output memcached-1.6.9.tar.gz
```bash

After download finished, Extract downloaded file using command below

```bash
tar xzf memcached-1.6.9.tar.gz

Go to the new directory

cd memcached-1.6.9/
```bash

Run `configure` to the code before we can compile memcached.

We will use `--prefix=/opt/memcached` so memcached binary and libraries will be installed on `/opt/memcached` instead of `/usr/local`

```bash
./configure --prefix=/opt/memcached

After configuration complete. let’s compile Memcached

make
```bash

```bash
$ ./memcached --version
memcached 1.6.9

To install memcached we can use command below

sudo make install
```bash

We need to use sudo since we're installing on `/opt` directory.

## Compiling Memcached With Latest Version of Libevent {#h-compiling-memcached-with-latest-version-of-libevent}

Memcached use [libevent][3] library. The one shipped with ubuntu is [version 2.1.8][4]

We can use latest version of Libevent to compile memcached. If you're wondering why compile memcached with latest version of libevent? for now just because we can.

I haven't done any benchmark to compare memcached compiled with libevent shipped with ubuntu 18.04 and memcached compiled with latest version of libevent.

Let's get started. Download libevent 2.1.8 using wget

```bash
wget -c https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz

Extract downloaded file

tar xzf libevent-2.1.12-stable.tar.gz
```bash

Go to the extracted directory

```bash
cd libevent-2.1.12-stable

Before we run configure, we need to install libssl-dev package. Since this version of libevent needs openssl headers. We can install libssl-dev using the command below.

sudo apt-get install libssl-dev
```bash

Run configure with `--prefix` option since we want to install libevent on `/opt/libevent` instead of on default path.

```bash
./configure --prefix=/opt/libevent

Compile libevent using make

make
```bash

Install compiled libevent

```bash
sudo make install

We assume you already download source code of Memcached 1.6.9. Extracted the compressed source code

tar xzf memcached-1.6.9.tar.gz 
```bash

Go to the new directory

```bash
cd memcached-1.6.9/

We run ./configure with prefix and with-libevent option

./configure --prefix=/opt/memcached --with-libevent=/opt/libevent
```bash

Compile memcached source using `make`

```bash
make

We can test whether memcached already compiled successfully by checking version using command below

./memcached --version
```bash

To install compiled memcache we will use make with install option.

```bash
make install

References  

  • Memcached website
  • libevent website

Summary  

In this tutorial we learned how to compile memcached from source on Ubuntu 18.04 (Bionic Beaver). We also tried to compile latest stable release of libevent and compile memcached with compiled libevent. Until next time.

 How To Install Skype on Ubuntu 20.04
How To Install Memcached From Source on Ubuntu 20.04 
On this page:
Overview   Prerequisite   Install Tools and Dependencies   References   Summary  
Follow me

We publish tutorials, tips and tricks about Linux, open source, cloud computing, and infrastructure

     
Copyright © 2012 - 2025 howtodojo.com. |
Howtodojo
Code copied to clipboard