How to Install Redis on Ubuntu

logo-130358959041456944If you’re running Ubuntu, there’s a good chance the version of Redis available in the repo is pretty old. Here’s how you can install the latest version of Redis on your Ubuntu or Debian box – these instructions should work on any Linux server.

On Debian or Ubuntu, make sure you have the ability to compile source code.

sudo apt-get install make gcc g++

Create a directory where you want to download and compile Redis. I usually go with a tmp directory in my home directory.

In the directory (e.g. ~/tmp/redis), run this.


Extract the tarball.

tar xvzf redis-stable.tar.gz

Compile the source.

cd redis-stable

Run the tests to make sure everything is good.

make test

Install Redis.

sudo make install

Create a redis user.

sudo useradd -s /bin/false -d /var/lib/redis -M redis

Create Redis pid, config and log directories. If you already installed Redis at some point, you might not need to do the following, but you can figure that out for yourself.

sudo mkdir /var/run/redis/ -p; sudo chown redis:redis /var/run/redis
sudo mkdir /etc/redis; sudo chown redis:redis /etc/redis -Rf
sudo mkdir /var/log/redis/ -p; sudo chown redis:redis /var/log/redis/ -Rf
sudo mkdir /etc/redis;
sudo cp redis.conf /etc/redis/redis.conf; sudo chown redis:redis /etc/redis/redis.conf

Create /etc/redis/redis.conf that looks like this.

daemonize yes
pidfile /var/run/redis/
loglevel warning
logfile /var/log/redis/redis.log
port 6379
dir /var/lib/redis

Create an init Upstart script that looks like this. Obviously, you don’t have to use Upstart, it’s actually being phased out in favor systemd, but you can decide how you want to fire up Redis on your server, here’s one option.

description "Redis server"
start on runlevel [2345]
stop on runlevel [!2345]
expect fork
respawn limit 10 5
exec sudo -u redis /usr/local/bin/redis-server /etc/redis/redis.conf

Fire it up.

sudo service redis start

Make sure it’s working.

redis-cli ping

If you don’t get a PONG, verify you did all of the steps correctly, if you did, head over to Google and start searching.

Based on the Upstart script, Redis should start on boot and restart on crash.

(h/t) I got a lot of information from this blog.

Share Button

Leave a Reply

Your email address will not be published.