How to set up Redis on Ubuntu!

How to set up Redis on Ubuntu!
Photo by josh Glauser / Unsplash


Redis is 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 for 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 the source code. If you want to set it 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 the source code to /tmp.

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

Compile and Setup

make test
sudo make install


After the setup, we need to configure Redis. To save the configuration files, we need to create /etc/redis a directory. 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.

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 the one below and then 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 the green "Active: active (running)" message.

Test with CLI

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


let's ping it;> ping



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

Output is;


Give it back to me;> 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.