How to Install Redis on Ubuntu

How to Install Redis on Ubuntu

Introducation

Redis is a powerful, open-source, in-memory data store widely used for caching, real-time analytics, and as a message broker. Installing Redis on Ubuntu is straightforward, but for optimal performance and security, a few configuration steps are recommended. Here’s a comprehensive, blog-ready guide to get Redis up and running on your Ubuntu server.

1. Update the APT Repository

Before installing any new packages, it’s best practice to update your local package index to ensure you’re getting the latest versions:

sudo apt update

This command refreshes the list of available packages and their versions.

2. Install the Redis Server

Install Redis from the official Ubuntu repositories using the following command:

sudo apt install redis-server

Press y and hit Enter when prompted to confirm the installation. This command will install Redis along with all necessary dependencies.

3. Verify the Redis Installation

After installation, check the Redis CLI version to confirm a successful setup:

redis-cli --version

You should see output displaying the installed version of the Redis CLI.

4. Manage the Redis Service

Redis is installed as a systemd service and starts automatically. To check its status, run:

sudo systemctl status redis-server

Look for the line Active: active (running) in the output to confirm Redis is running. If the service isn’t active, you can start or restart it:

sudo systemctl start redis-server
sudo systemctl restart redis-server

To ensure Redis starts automatically on boot, enable the service:

sudo systemctl enable redis-server

If you need to stop Redis at any point, use:

sudo systemctl stop redis-server

5. Basic Redis Usage Test

To test if Redis is working, use the Redis CLI:

redis-cli

At the prompt, type:

ping

If Redis is running, it will reply with:

PONG

6. (Optional) Secure and Configure Redis

After installation, it’s recommended to adjust some default settings for security and performance.

  • Edit the Redis configuration file:
sudo nano /etc/redis/redis.conf
  • Set supervised directive:
    For better service management, find the supervised directive and set it to systemd:
supervised systemd
  • This change allows Redis to be managed reliably by systemd.
  • Configure authentication (optional but recommended):
    Set a password by adding or editing the requirepass directive in the config file:
requirepass your_secure_password

Restart Redis to apply changes:

sudo systemctl restart redis-server

7. (Optional) Allow Remote Connections

By default, Redis listens only on localhost for security reasons. To allow remote connections:

  • Open /etc/redis/redis.conf
  • Find the bind directive and add your server’s IP address, or comment it out to listen on all interfaces (not recommended for production without firewall rules).
  • Set protected-mode no if you must allow remote connections (again, not recommended without proper security).

Always secure your Redis instance with a strong password and firewall rules if enabling remote access.

8. (Optional) Install Redis Client Tools

If you only need the Redis CLI to connect to a remote Redis server, install just the client tools:

sudo apt install redis-tools

Summary Table: Key Commands

TaskCommand
Update APT repositorysudo apt update
Install Redis serversudo apt install redis-server
Check Redis versionredis-cli –version
Check Redis statussudo systemctl status redis-server
Start Redissudo systemctl start redis-server
Restart Redissudo systemctl restart redis-server
Enable Redis on bootsudo systemctl enable redis-server
Stop Redissudo systemctl stop redis-server
Open Redis CLIredis-cli
Test Redis (ping)ping (inside redis-cli)
Edit config filesudo nano /etc/redis/redis.conf
Install client toolssudo apt install redis-tools

Conclusion

By following these steps, you’ll have a robust Redis installation on your Ubuntu system, ready for development or production use. For enhanced security and performance, always review and adjust the configuration file as needed, and consider setting up proper firewall rules if you plan to allow remote access.

READ MORE:- How to install Odoo and OpenEduCat on Ubuntu: A Step-by-Step Guide

Leave a Reply

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

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.