How to setup Redis on Ubuntu!

Step by step Redis setup.


Redis is a software used for database or caching that stores a key-value running in-memory. Click for more details


We need a machine with Ubuntu 16.04 installed a non-root user with sudo authority in order to have Redis working in your hand.

Pre Setup and Test

I prefer to set up Redis from source code. If you want to set up via OS package manager or Homebrew I'll add those later.

First of all we need to install some packages.

  • build-essential
  • tcl

As we always do, we get updates first.

sudo apt-get update
$ sudo apt-get install build-essential tcl


I prefer to download source code to /tmp.

cd /tmp
$ curl -O
$ tar xzvf redis-stable.tar.gz

Compile and Setup

While into /tmp directory, executing commands below

$ make test


sudo make install


After the setup, we need to configure Redis. To save the configuration files, we need to create /etc/redisdirectory. To do this;

sudo mkdir /etc/redis

Copy the sample configuration files to the directory we just created.

sudo cp /tmp/redis-stable/redis.conf /etc/redis

Open and start editing the file.

sudo nano /etc/redis/redis.conf

In Configuration File;

We need to changecode supervised no to supervised systemd Because Ubuntu using systemd init.

Also change dir ./ todir /var/lib/redis. This line indicates where permanent data is stored. Save and close the configuration file.

Creating Systemd Unit File

We need to edit redis.service file like below and than save it. (Typical service definition)

sudo nano /etc/systemd/system/redis.service
Description=Redis standalone

ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown


Redis User/Group/Path Definitions

To create a user;

sudo adduser --system --group --no-create-home redis

To create a directory

sudo mkdir /var/lib/redis

To create ownership;

sudo chown redis:redis /var/lib/redis

To change write permission;

sudo chmod 770 /var/lib/redis

Starting Redis and Checking the Status

To start;

sudo systemctl start redis

To status check;

sudo systemctl status redis

When you execute the last command, you need to see green "Active: active (running)" message.

Test with CLI

Redis CLI is a client tool to communicate with the Redis server. To execute;


lets ping it;> ping



Let's continue with the data test.> set test "Habil"

Output is;


Give it to me back;> get test



Starting Redis Service on Boot-up

$ sudo systemctl enable redis

The End

We currently have a fully working Redis installation in our operating system. If you wish, you can take a look at official documents.