How to Install Redis on Ubuntu 18.04 Bionic Beaver

Install Redis on Ubuntu 18.04 Bionic Beaver

In this article, we will have explained the necessary steps to install and configure Redis on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Redis (Remote Dictionary Server) is an open-source, in-memory database that is used as a cache and message broker. Some of Redis features are built-in transactions, replication, and support for a variety of data structures like strings, hashes, lists, sets and so on. Redis Sentinel makes Redis highly available and it supports automatic partitioning with Redis Cluster.

Install Redis on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Redis.

Redis package is available in default repository in Ubuntu 18.04. So to install Redis run below command:

sudo apt install redis-server

Once the installation is completed, the Redis service will start automatically. To confirm installation and check Redis status run below command:

sudo systemctl status redis-server

Step 3. Configure Redis.

First, run below command and open Redis configuration file:

sudo nano /etc/redis/redis.conf
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0 ::1

To take changes effect, restart Redis server by running below command:

sudo systemctl restart redis-server

Use the following ss command to verify that the Redis server is listening on your private interface on port 6379:

ss -an | grep 6379

You should see something like below:

tcp    LISTEN     0      128    192.168.121.233:6379            *:*
tcp    LISTEN     0      128    127.0.0.1:6379                  *:*

Next, we will setup UWF firewall for accessing Redis from a remote host:

sudo ufw allow proto tcp from 192.168.121.0/24 to any port 6379

To verify that everything is setup properly, you can try to ping the Redis server from your remote machine using the redis-cli utility which provides a command-line interface to a Redis server:

redis-cli -h <REDIS_IP_ADDRESS> ping

You should see exact below output:

PONG

That’s all you need to do to install Redis on Ubuntu 18.04 Bionic Beaver. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.