UbuntuUbuntu Based

How To Install Redis on Ubuntu 24.04 LTS

Install Redis on Ubuntu 24.04

In this tutorial, we will show you how to install Redis on Ubuntu 24.04 LTS. Redis (Remote Dictionary Server) is a high-performance, key-value data store that supports various data structures like strings, hashes, lists, sets, and more. It is designed for speed and efficiency, making it an excellent choice for applications that require real-time data processing and low-latency operations.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Redis on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • Basic familiarity with the terminal and command-line interface.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Redis on Ubuntu 24.04

Step 1. Updating the Package Repository.

Keeping your system up-to-date is crucial for maintaining security and ensuring compatibility with new software installations. Before installing Redis, update your system packages using the following commands:

sudo apt update
sudo apt upgrade -y

 These commands will refresh your package lists and upgrade all installed packages to their latest versions. The -y flag automatically answers “yes” to any prompts, streamlining the upgrade process.

Step 2. Installing Redis.

Ubuntu’s default repositories include Redis, making the installation process straightforward. Follow these steps to install Redis using the APT package manager:

sudo apt install redis-server

Once the installation is complete, verify it by checking the Redis version:

redis-server --version

This command should display the installed Redis version, confirming a successful installation.

Step 3. Configuring Redis.

Proper configuration is essential for optimal Redis performance and security. The main Redis configuration file is located at /etc/redis/redis.conf. Let’s explore some key configuration options:

sudo nano /etc/redis/redis.conf

By default, Redis binds to localhost. To allow remote connections, find the line:

bind 127.0.0.1

And change it to:

bind 0.0.0.0

Redis typically runs on port 6379. You can change this by modifying the port directive:

port 6379

Redis offers two persistence mechanisms: RDB and AOF. Configure these based on your data durability requirements:

save 900 1
save 300 10
save 60 10000
appendonly yes

It’s crucial to secure your Redis instance with a strong password. Find the following line in the configuration file:

requirepass your_strong_password

By default, Redis is configured to listen only on the local interface. To enable remote access, open the Redis configuration file (/etc/redis/redis.conf) and locate the following line:

bind 127.0.0.1 ::1

Comment out this line or replace 127.0.0.1 with the IP address of the network interface you want Redis to listen on.

To start the Redis service manually, run the following command:

sudo systemctl start redis-server

To ensure that Redis starts automatically on system boot, run the following command:

sudo systemctl enable redis-server

You can check the status of the Redis service using the following command:

sudo systemctl status redis-server

Step 4. Testing Redis Installation.

To test your Redis installation, connect to the Redis command-line interface (CLI) by running the following command:

redis-cli

If you’ve set a password, authenticate using the AUTH command:

AUTH your_password

Once connected, you can execute basic Redis commands to ensure that everything is working correctly. Here are a few examples:

SET key value
GET key

These commands set a key-value pair and retrieve the value associated with a key, respectively.

To test Redis persistence, you can set a key-value pair, exit the CLI, and then reconnect to see if the data persists:

SET test "Hello, Redis!"
EXIT
redis-cli
GET test

If the value is retrieved successfully, it confirms that Redis persistence is working as expected.

Step 5. Firewall Considerations.

If you have a firewall enabled, ensure that the Redis port (default: 6379) is open for incoming connections. You can use the following command to allow access to the Redis port:

sudo ufw allow 6379

Congratulations! You have successfully installed Redis. Thanks for using this tutorial for installing Redis on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Redis website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button