How Install Redis

By Michele Berardi
Picture of the author
Published on
image alt attribute

How to Install Redis on Ubuntu and CentOS

Introduction

Redis is a popular open-source, in-memory data structure store, used as a database, cache, and message broker. This guide will walk you through the steps to download and install the latest version of Redis on two widely-used Linux distributions: Ubuntu and CentOS.

Part 1: Installing Redis on Ubuntu

Step 1: Update System Packages

Before installing Redis, it's a good idea to update your package lists:

sudo apt update

Step 2: Install Redis

Install Redis by running the following command:

sudo apt install redis-server

Step 3: Verify Redis Installation

Once installed, you can check that Redis is running with:

redis-cli ping

If Redis is running, it will return a PONG response.

Step 4: Configure Redis (Optional)

You can configure Redis by editing its configuration file:

sudo nano /etc/redis/redis.conf

After making changes, restart Redis to apply them:

sudo systemctl restart redis-server

Part 2: Installing Redis on CentOS

Step 1: Add the EPEL Repository

First, add the EPEL (Extra Packages for Enterprise Linux) repository:

sudo yum install epel-release

Step 2: Install Redis

Install Redis using YUM:

sudo yum install redis

Step 3: Start and Enable Redis

Enable Redis to start on boot and then start the service:

sudo systemctl start redis
sudo systemctl enable redis

Step 4: Verify Redis Installation

Check if Redis is functioning:

redis-cli ping

A successful installation should return PONG.

Step 5: Configure Redis (Optional)

Similar to Ubuntu, edit the configuration file to tweak Redis settings:

sudo nano /etc/redis.conf

Restart the Redis service after making changes:

sudo systemctl restart redis

Part 3: Installing Redis via tar.gz

For Both Ubuntu and CentOS

Step 1: Download the Latest Version

Download the latest version of Redis from the official website. Here, we use Redis 5.0.3 as an example:

wget http://download.redis.io/releases/redis-5.0.3.tar.gz

Step 2: Extract the Package

Extract the downloaded package:

tar zxvf redis-5.0.3.tar.gz
cd redis-5.0.3

Step 3: Compile Dependencies

Compile the necessary dependencies:

cd deps
make hiredis jemalloc linenoise lua geohash-int
cd ..

Step 4: Install Redis

Install Redis on your system:

make install

Step 5: Setup Redis Server

Run the installation script to set up the Redis server:

cd utils
./install_server.sh

Step 6: Start Redis Server

Start the Redis server:

systemctl start redis_6379
systemctl status redis_6379

Step 7: System Configuration (Optional)

To optimize performance, you can modify system configurations:

  • Add 'vm.overcommit_memory = 1' to /etc/sysctl.conf.
  • Run sysctl vm.overcommit_memory=1 to apply the change immediately.
  • Note: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

Conclusion

You now have the knowledge to install Redis on Ubuntu and CentOS using different methods, including via package manager and directly from the source. Each method has its advantages, and the choice depends on your specific requirements and environment.

Stay Tuned

Want to become a AI pro?
The best articles, links and news related to AI delivered once a week to your inbox.