How To Install & Configure Redis in Ubuntu 16.04

We show you the steps you must follow to install and configure Redis on Ubuntu 16.04

Redis is Open Source application, which is licensed by BSD through which we can use it as a database, messaging client, and other essential functionalities.

Main Features

  • Redis supports data structure such as chains, hashes, lists among many others.
  • Great flexibility
  • Supports multiple languages
  • Redis can perform atomic operations such as increasing the value of a hash, append values to strings, add an element to a specific list, etc.
  • Supports asynchronous master/slave replications
  • Automatic recovery in case of failures
  • High performance.

Download, Compile & Install Redis in Ubuntu 16.04

To have the latest version of Redis, it will be necessary to install in Ubuntu 17.10 the build-essential meta-package from the official Ubuntu repositories. Additional download the tcl component for the use of binaries. For this we will execute the following commands in their order including the operating system update:

sudo apt-get updatesudo apt install build-essential tcl

The next step is to download and install Redis in the system. First we will move to the / tmp directory:

cd /tmp

Once there we proceed to download the latest stable version of Redis by running the following command:

curl -O

Unzip the file by executing the following command:

tar xzvf redis-stable.tar.gz

Now we will move to the Redis structure that we have just decompressed using the following command:

cd redis-stable

Once there, we will proceed to build the Redis structure and its subsequent installation, execute make on that route and start the Redis compilation process.

We run make test to make sure everything is working in the best way.

Now we proceed to install the binaries by executing the following command:

sudo make install

Configure Redis in Ubuntu 16.04

Once Redis is installed, the next step will be to carry out the configuration process, for this we will create the / etc / redis directory using the following command:

sudo mkdir /etc/redis

We proceed to copy the Redis configuration file in the previously created directory:

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

We open the respective file for its configuration with the preferred editor:

sudo nano /etc/redis/redis.conf

In this file, we will locate the supervised line.

There we will modify the no by systemd:

Now we will locate the line dir directory which is where Redis dumps all the persistent data.

There we must indicate a route where Redis has write permissions and is not readily visible by the users, we will select the path


We save the changes in the file Ctrl + O and exit the file Ctrl + X.

Create Redis Systemd File Drive

This unit will ensure that the init system can manage the Redis processes. For this we will create and open the following file, redis. Service, where we will configure the respective processes of the unit:

sudo nano /etc/systemd/system/redis.service

Once the indicated file is opened, we will create the [Unit] line where we will add a description of the process and the network requirement will be defined before starting the service, we will enter the following:

[Unit]Description=Redis In-Memory Data

Now we will add a section called [Service] where we will indicate the way in which the service will unfold in Redis. It is important, for security issues of Ubuntu, that we do not start the service with the root user, so we will create standard users for this purpose called redis.

For the service to be initialized we must invoke the binary redis-server which will be configured in this section. To stop the service we will use the Redis Shutdown command which will be executed with the redis-cli binary. Finally, for Redis to have the ability to restore itself in case of errors, we will establish the Restart policy in Always, this will be what we add in that section:

[Service]User=redisGroup=redisExecStart=/usr/local/bin/redis-server /etc/redis/redis.confExecStop=/usr/local/bin/redis-cli shutdownRestart=always

Finally in the [Install] section we will indicate the destination of the system in which the service will be attached if it is enabled, we will enter the following:


We save the changes in the file and left the file.

Create Redis Groups, Users & Directories

The next step is the creation of the elements with which the Redis service will start.
To create the user and the Redis group we will execute the following command:

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

Now we will create the / var / lib / redis directory by running the following command:

sudo mkdir /var/lib/redis

We configure that the user and group redis own this directory by executing the following command:

sudo chown redis:redis /var/lib/redis

Finally we set the permissions on the directory so that no different user has access, for it we run the next line:

sudo chmod 770 /var/lib/redis

Start & Test

Once we have configured the previous step we must start the Redis service by executing the following command:

sudo systemctl start redis

We verify that the service does not present errors by executing the following command:

sudo systemctl status redis

The result will be the following:

We check that his state is active (running).

Start Redis Automatically

If we want Redis to be executed automatically in Ubuntu, we will execute the following command:

sudo systemctl enable redis

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *