How to install and configure Redis on Ubuntu 20.04

s2 0

Redis is an open source in-memory key-value data store. It can be used as a database, cache and message broker and supports various data structures such as strings, hashes, lists, sets and more. Redis offers high availability via Redis Sentinel and automatic partitioning across multiple Redis nodes with Redis Cluster.

This tutorial describes how to install and configure Redis on Ubuntu 20.04.

Install Redis on Ubuntu 20.04

Installing Redis on Ubuntu is a straightforward process.

Redis version 5.0.x is included in the standard Ubuntu 20.04 repositories. To install it, run the following commands as root or user with sudo privileges:

sudo apt updatesudo apt install redis-server

Once the installation is complete, the Redis service will start automatically. Enter the following command to check the status of the service:

sudo systemctl status redis-server

You should see something like this:

● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-06-06 20:03:08 UTC; 10s ago
The Redis service will not start if IPv6 is disabled on your server.

That’s it. You have installed and running Redis on your Ubuntu 20.04 server.

Configure Redis remote access

By default, the Redis server does not accept remote connections. You can only connect to Redis from (localhost) – the machine Redis is running on.

If you are using a single server setup where the client that connects to the database is also running on the same host, you should not enable remote access.

To configure Redis to accept remote connections, open the Redis configuration file with your text editor:

sudo nano /etc/redis/redis.conf

Find the line that starts with bind ::1 and comment on it.

# bind ::1
If your server has a private IP and you want Redis to only be reachable from the private network, instead of commenting on the line that says the private IP address after

Save the file and restart the Redis service for the changes to take effect:

sudo systemctl restart redis-server

Use the following command to check that redis is listening on port on all interfaces 6379:

ss -an | grep 6379

You should see something like below. means all IPv4 addresses on the device.

tcp  LISTEN 0   511*
tcp  LISTEN 0   511      [::]:6379      [::]:*  

Next, you need to configure your firewall to enable traffic on the TCP port 6379.

Typically, you want to allow access to the Redis server only from a specific IP address or range. For example, to connect only from the subnet, you would run the following command:

sudo ufw allow proto tcp from to any port 6379
Make sure your firewall is configured to only accept connections from trusted IP ranges.

At this point you should be able to connect to Redis remotely using TCP port 6379.

To check that everything is set up correctly, you can try running the Redis server from your remote machine with the redis-cli Utility:

redis-cli -h <REDIS_IP_ADDRESS> ping

The command should return a response from PONG:



We showed you how to install Redis on Ubuntu 20.04. For more information on managing your Redis installation, see Redis documentation

If you run into any problem or have any feedback, please leave a comment below.