Quick Guide: Install and Configure Redis on Ubuntu

Written by Christophe Limpalair on 08/29/2015

Introduction
Redis is an open source data structure server. A what? Glad you asked!

Redis is essentially a NoSQL key-value data store. Unlike MongoDB (which is disk-based), Redis stores key-values in memory making it very fast to read and write.

If you’re familiar with Memcached, you may think it sounds very similar, but Redis has a few powerful advantages. For one, Redis has built-in persistence, so you can back up your data to disk and not risk losing it. This also means that you can use Redis as a real database instead of just a cache system. Just in case that wasn’t enough, Redis offers even more data types than Memcached.

While I could go on listing all the incredible benefits and features Redis has to offer, I’ll save that for another post. In this post, I’ll walk you through the steps of installing and configuring Redis on a Ubuntu server. It’s a straightforward process, so let’s get started!

This guide will assume you have a running Ubuntu 14.04 LTS server with a user that has sudo privileges or access to sudo. If you do not already have this setup, learn how to quickly install Ubuntu server on a Virtual Machine.

Step 1: Install Redis
Download, extract and compile Redis:

wget http://download.redis.io/releases/redis-2.8.19.tar.gz

tar xzf redis-2.8.19.tar.gz

sudo mv redis-2.8.19 /etc/redis

cd /etc/redis

sudo apt-get install make

sudo apt-get install gcc

sudo aptitude install build-essential

sudo make




It will run for a few minutes so grab a coffee! You should then see "Hint: To run ‘make test’ is a good idea ;) ".

This one step is optional and takes a few minutes, but I’m going to do it for this article. When I run make test, I get an error:

You need tcl 8.5 or newer in order to run the Redis test


If you also get that error, install tcl8.5:

sudo apt-get install tcl8.5


Run make test again (optional). It will go through and test a bunch of stuff. This may take a few minutes.

After that finishes, run:

sudo make install


Step 2: Start Redis
Once you’ve completed all the previous steps, Redis will have a built in script that sets up Redis to run as a background daemon. Access it with:

cd utils


sudo ./install_server.sh


It will then run you through a set of questions. If you want to leave the options as default, just press enter at each prompt. This is what I’m going to do.

You should see:

Success!
Starting Redis server…
Installation successful!


Redis automatically started so you don’t have to do anything else, but just for future reference:

sudo service redis_6379 start
sudo service redis_6379 stop


redis_6379 number is the default port. If you used a different port number, use that.

You can now play around with the Redis command line interface:
redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> SET user:name "Christophe"
OK
127.0.0.1:6379> GET user:name
"Christophe"


For more commands, check out a "mock" Redis CLI tutorial that gives you a realistic and more in-depth view of Redis features.

Simple Use Cases to learn from
Here's one use case that I promised. This use case will show you how to use Redis for caching user views. This will save your database from thousands of READS and WRITES.

Here's a screencast series on Redis use cases. I walk you through practical use cases like:
1) Tagging articles, products, or movies
2) Caching database queries to improve page load times and reduce the stress on your DB
3) and a lot more