How to install Redis on a Linux cloud server?

08-02-2024 03:02:51

Redis is an open-source, in-memory data dictionary service similar to Memcached for storing key-value pairs. It is a NoSQL database. This guide explains how to install and use Redis on a Linux cloud server, applicable to operating systems such as CentOS, Fedora, Ubuntu, Debian, etc.

CentOS/Fedora

Install the Remi software repository, which usually provides a newer version of Redis compared to the official CentOS software repository.

$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Check the Redis-related packages available in the Remi software repository, where the second column corresponds to the Redis version.

$ dnf module list | grep redis
redis     5 [d]        common [d]     Redis persistent key-value database
redis     remi-5.0     common [d]     Redis persistent key-value database
redis     remi-6.0     common [d]     Redis persistent key-value database

Taking Redis 6.0 as an example, use the following command to install:

$ sudo dnf module install redis:remi-6.0 -y

Start the Redis service and configure it to start automatically with the system.

$ sudo systemctl start redis.service 
$ sudo systemctl enable redis.service 

Ubuntu

The Redis version available in the official Ubuntu software repository is often older than the latest version. Here, we will use the chris-lea/redis-server software package, a community-supported PPA.

$ sudo add-apt-repository ppa:chris-lea/redis-server

Update and install Redis using the following commands:

$ sudo apt-get update
$ sudo apt-get install redis-server -y

Configure the Redis service to start automatically with the system.

$ sudo systemctl enable redis-server.service 

Debian

Install the stable version of Redis:

$ sudo apt-get update
$ sudo apt-get install redis-server -y

Install the latest version of Redis:

$ echo 'deb http://deb.debian.org/debian buster-backports main' | sudo tee /etc/apt/sources.list.d/backports.list
$ sudo apt-get update
$ sudo apt-get -t buster-backports install redis-server -y