How to Install and Configure Redis on Ubuntu 24.04
Redis is an open-source, powerful database system that uses your main computer memory to store data. Redis is a pretty fast and reliable tool that can be used as a cache, database, or message broker and works well with different web applications. It allows users to quickly access data, such as managing sessions on websites or speeding up how fast a specific website loads.
Redis is ideal for Linux systems including Ubuntu 24.04 because it can be easily installed and worked well with the system. Redis will help applications running on Ubuntu to perform better by quickly accessing data from the memory instead of slower disk storage. Apart from that, it also supports multiple programming languages, thus making it a versatile tool for different projects.
Read this guide to learn:
How to Install and Configure Redis on Ubuntu 24.04
The Ubuntu standard apt repository includes the Redis package that can easily be installed through the apt install command. You can follow the below-given steps to install and configure Redis on Ubuntu from the apt repository:
Step 1: Update Ubuntu Repository
Before beginning the Redis installation on Ubuntu 24.04, first update the standard system repository using the following command:
sudo apt update && sudo apt upgrade -y
Step 2: Install Redis on Ubuntu
After updating the repository, you can install Redis on Ubuntu directly from the apt repository by using the below-given command:
sudo apt install redis-server -y
:
Step 3: Confirm Redis Installation on Ubuntu
Once you complete the Redis installation on Ubuntu, use the below-given command to confirm the installation:
redis-server --version
Note: You can also install Redis on Ubuntu from Snap Store using the following command:
sudo snap install redis
Step 4: Setting up Redis Server on Ubuntu
The supervised directive inside the Redis configuration file allows you to declare the init system for managing Redis as a service. You can open this configuration file using the following command and look for the supervised directive:
sudo nano /etc/redis/redis.conf
By default, it is set to auto, allowing the system to detect upstart or systemd methods. You can leave the supervise directive to auto for automatic selection:
Or, simply change it from auto to systemd, as shown below:
Once done, save the Redis configuration file by using CTRL+X, add Y and press Enter.
Step 5: Restart the Redis Server on Ubuntu
After saving the changes in the Redis configuration file, restart the Redis server using the following command to apply those changes:
sudo systemctl restart redis.service
You can then check whether Redis service is actively running on the system by using the below-given command:
sudo systemctl status redis.service
Step 6: Test the Working of Redis Server on Ubuntu
To ensure the Redis server is working on Ubuntu, you can test it by first connecting to the Redis server using the following command:
redis-cli
Then use the ping command to test the connectivity of Redis server:
ping
When you run the ping command, it will reply with the message PONG that ensures that Redis service is running on the system:
Next, let’s try out whether we can set a key called test by running the following command:
set test "Redis is working"
The above command will return the output as OK, ensuring the key is set:
You can then retrieve the key value by using the get command followed by the key name:
get test
To exit the process, use the exit or quit command:
Step 7: Connect to Redis Remotely
By default, the Redis server is only accessible through the local host, this prevents you from remotely accessing Redis. You can change the settings and allow Redis to access from anywhere by first opening the Redis configuration file using the following command:
sudo nano /etc/redis/redis.conf
Then inside the file, find the following line:
bind 127.0.0.1 ::1
Replace 127.0.0.1 ::1 with 0.0.0.0 for remotely allow connections:
Further, find the line protective-mode yes and change yes to no to allow connecting to Redis from other computers.
Once done, you can save the changes by saving the file using CTRL+X, add Y and press Enter. Then restart the Redis service on Ubuntu by using the following command:
sudo systemctl restart redis.service
You can verify the changes by running the following command:
sudo ss -an | grep 6379
You should also allow the inbound traffic on port number 6379 through Firewall (UFW) using the following command:
sudo ufw allow 6379/tcp
Note: You can install UFW on Ubuntu using the following command:
sudo apt install ufw -y
Then reload the UFW using the below-given command to apply the changes:
sudo ufw reload
Once done, open the terminal on your other computer, install Redis if required, and connect to the remote server using the following command:
redis-cli -h host-ip-address
Ensure to replace the host-ip-address with the IP address of the Ubuntu system where Redis is installed and configured. You can find the IP address of the Ubuntu system using the following command:
hostname -I
Step 8: Configuring Authentication for Redis
By default, the authentication is disabled for Redis, thus allowing everyone to access the store data without entering a password. To increase the privacy of your data, it is recommended to add a password for authentication purposes. You can configure authentication for Redis by opening the configuration file using:
sudo nano /etc/redis/redis.conf
Inside this file, search the following line:
requirepass foorbared
Uncomment the line by removing the # sign and add your password in place of foorbared:
Then save the file and connect to Redis through the redis-cli command. When you run the command at redis-cli for accessing the data, you will get the Authentication error:
To fix the error, first, authenticate yourself using the auth command followed by the password you previously set:
auth password
When you get an OK reply in return, it ensures that you have successfully authenticated yourself for Redis. After the authentication, you can then be able to use the Redis command to authenticate.
At this stage, you have successfully configured Redis on Ubuntu 24.04.
Note: In case you want to remove Redis from the Ubuntu 24.04 system, you can simply use the below-given command:
sudo apt remove redis-server -y
Conclusion
Redis is a robust database system used for caching and storing data structures in memory. You can install Redis on Ubuntu 24.04 directly from the Ubuntu standard repository. After the installation, you may need to edit the Redis configuration file to enable its service on the Ubuntu system. Once the service is enabled, you can then test the working of Redis, remotely access the Redis server, or enable the authentication feature for Redis. We have provided the complete details for all these methods in the above section of this guide. Following the details will help you ensure smooth working with Redis on the Ubuntu system.
























