How to Install Redis on Ubuntu 24.04

Redis is an in-memory data structure store that serves as a database, cache, and message broker. It supports various data structures like strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes. Redis is known for its performance, flexibility, and simplicity, making it a popular choice for developers and system administrators.

This guide shows you how to install and configure Redis on an Ubuntu 24.04 server.

Prerequisites

To get started, ensure you have the following:

Install Redis

This section shows you how to install Redis on Ubuntu 24.04. The Redis package is available in the default Ubuntu repository, making it straightforward to install using the apt package manager.

  1. Update the package index.

    CONSOLE
    $ sudo apt update
    
  2. Install the Redis package.

    CONSOLE
    $ sudo apt install redis-server
    
  3. Verify the installation.

    CONSOLE
    $ redis-server --version
    

Manage the Redis Service

Redis runs under redis. In this section, you will manage the service using systemctl, the system and service manager for Ubuntu.

  1. Start the Redis service.

    CONSOLE
    $ sudo systemctl start redis
    
  2. Enable Redis to start on boot.

    CONSOLE
    $ sudo systemctl enable redis
    
  3. Check the status of the Redis service.

    CONSOLE
    $ sudo systemctl status redis
    

Secure the Redis Server

By default, Redis does not require a password, which can pose security risks. This section explains how to secure your Redis server by setting a password.

  1. Open the Redis configuration file in a text editor.

    CONSOLE
    $ sudo nano /etc/redis/redis.conf
    
  2. Find the requirepass directive.

    INI
    # requirepass your_secure_password
    
  3. Uncomment the requirepass directive by removing the # at the beginning. Then, set a strong password.

    INI
    requirepass your_secure_password
    
  4. Save the changes and close the editor.

  5. Restart the Redis service to apply the changes.

    CONSOLE
    $ sudo systemctl restart redis
    

Understand Redis Directory Structure

The following details show the Redis directory structure, including configuration, error, and log files.

  • Redis configuration file: /etc/redis/redis.conf. A file that contains all the settings for the Redis server.
  • Redis data directory: /var/lib/redis. A directory that stores the data files used by Redis.
  • Redis log file: /var/log/redis/redis-server.log. A file that stores stores logs generated by the Redis server.

Log In to Redis and Perform Basic Operations

Test the Redis server by seting a key and retrieve the key's value to ensure Redis works as expected.

  1. Log in to the Redis server using the redis-cli command.

    CONSOLE
    $ redis-cli
    
  2. Authenticate with the password you set earlier.

    CONSOLE
    auth your_secure_password
    
  3. Set a sample test key in Redis.

    CONSOLE
    set test "Hello, Redis!"
    
  4. Retrieve the value of the test key you set.

    CONSOLE
    get test
    

Conclusion

You have successfully installed and configured Redis on your Ubuntu 24.04 server. You have learned how to manage the Redis service, secure it with a password, understand its directory structure, and perform basic operations like setting and retrieving keys. Redis is a powerful tool that can enhance your application's performance and scalability.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js