Redis is an open-source, in-memory data structure store commonly used as a database, cache, and message broker. It is known for its speed, flexibility, and ease of use, making it a popular choice for developers. Whether you’re setting up Redis to improve application performance or using it for caching, this guide will walk you through the steps to install Redis on Ubuntu system.
In this article, we’ll provide an easy-to-follow, detailed guide for install Redis on Ubuntu. You’ll learn everything you need to get Redis running smoothly, from the basics of installation to configuring and managing your Redis server.
What is Redis and Why Use It?
Redis (REmote DIctionary Server) is an in-memory NoSQL database designed for speed and flexibility. It stores data in various formats such as strings, hashes, lists, sets, and more, making it highly versatile. Redis is often used for caching frequently accessed data, improving the performance of applications by reducing the need to query slower storage systems like disk-based databases.
Key benefits of Redis include:
- Performance: Redis is known for its high performance due to its in-memory storage.
- Persistence Options: Redis offers both volatile memory storage and persistence options (snapshots and append-only files).
- Pub/Sub Messaging: Redis supports Publish/Subscribe messaging for real-time communication.
- Ease of Use: Redis has a simple set of commands, making it easy for developers to integrate into applications.
Now that you understand the basics, let’s dive into installing Redis on your Ubuntu system.
Prerequisites for Installing Redis
Before installing Redis, ensure you meet the following prerequisites:
- Ubuntu 20.04 or Later: This guide covers installation on Ubuntu 20.04 or later. Make sure your system is up-to-date.
- Root or Sudo Privileges: You’ll need administrative access to install software and configure services.
- A Basic Understanding of the Linux Command Line: Basic familiarity with the command line will help you navigate through the installation process.

How to Install Redis on Ubuntu?
There are two primary ways to install Redis on Ubuntu: via the official Ubuntu repository or by compiling Redis from the source. We’ll walk you through both methods, so you can choose the one that works best for you.
3.1 Installing Redis from the Ubuntu Repository
The easiest way to install Redis on Ubuntu is through the default APT repository. Redis is included in the Ubuntu software repositories, which makes it quick to install and update.
Step 1: Update Your Package List
Before installing Redis, it’s good practice to update your system’s package list to ensure you’re installing the latest versions of packages.
sudo apt update
Step 2: Install Redis Server
Next, install Redis using the following command:
sudo apt install redis-server
This command will download and install Redis along with its dependencies.
Step 3: Verify the Installation
Once the installation is complete, verify that Redis is running by checking its status:
sudo systemctl status redis
If Redis is running correctly, you’ll see a message indicating that the Redis service is active and running.
3.2 Installing Redis from Source
For more control over the version of Redis or if you want to install a specific version, you can install Redis from source. This method allows you to compile Redis yourself, ensuring you have the latest version or any custom configuration needed.
Step 1: Install Dependencies
Before installing Redis from source, make sure you have the required dependencies. You can install them by running:
sudo apt install build-essential tcl
Step 2: Download the Latest Stable Version of Redis
Next, download the latest stable version of Redis from the official Redis website. You can do this by running:
curl -O http://download.redis.io/redis-stable.tar.gz
Step 3: Extract the Tarball
After downloading, extract the Redis tarball:
tar xzvf redis-stable.tar.gz
cd redis-stable
Step 4: Compile Redis
Once inside the extracted directory, compile Redis by running:
make
If you want to run tests to ensure everything is working properly, you can run:
make test
Step 5: Install Redis
After compiling Redis, install it to your system:
sudo make install
This command installs Redis binaries to the appropriate locations on your system.
Step 6: Set Up Redis as a Service
Redis does not come with a systemd service file by default when you install from source. To configure Redis as a service, you can create a custom systemd service file. Here’s a basic configuration:
Create a file called redis.service
in the /etc/systemd/system/
directory:
sudo nano /etc/systemd/system/redis.service
Add the following content:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-server /etc/redis/redis.conf stop
Restart=always
[Install]
WantedBy=multi-user.target
Save and close the file, then reload the systemd manager:
sudo systemctl daemon-reload
Now, start Redis and enable it to start on boot:
sudo systemctl start redis
sudo systemctl enable redis
Starting Redis Service
If you installed Redis using APT, it should already be running. To start or restart Redis manually, use:
sudo systemctl start redis
sudo systemctl restart redis
You can also stop the Redis service with:
sudo systemctl stop redis
Verifying Redis Installation
To check that Redis is running correctly, you can use the redis-cli
command-line tool, which is included with the Redis installation. Run the following command to connect to the Redis server:
redis-cli
Once connected, type the following command to verify the server is responding:
ping
You should receive the response:
PONG
This confirms that your Redis server is up and running.
Configuring Redis
Redis comes with a default configuration file located at /etc/redis/redis.conf
. This file can be edited to modify various Redis settings, including memory management, persistence, and security.
Key Redis Configuration Options
- maxmemory: Limits the amount of memory Redis can use.
- appendonly: Enables persistence by writing all commands to an append-only file.
- requirepass: Sets a password for accessing the Redis server.
- bind: Restricts Redis to listen only on specific IP addresses.
To edit the Redis configuration, use a text editor such as nano:
sudo nano /etc/redis/redis.conf
Make your changes, save the file, and then restart Redis to apply the changes:
sudo systemctl restart redis
Securing Your Redis Installation
By default, Redis is not secured and listens on all IP addresses, making it vulnerable to unauthorized access. To enhance security:
- Bind Redis to Localhost: In the Redis configuration file, set
bind 127.0.0.1
to restrict access to localhost only. - Set a Password: Enable password protection by uncommenting and setting a strong password in the
requirepass
directive in the configuration file:requirepass your-strong-password
- Firewall Configuration: Ensure your firewall blocks external access to the Redis port (default 6379) unless it’s necessary.
Common Redis Commands
Here are some useful Redis commands to get started:
- SET key value: Stores a value associated with a key.
- GET key: Retrieves the value associated with a key.
- DEL key: Deletes a key.
- EXPIRE key seconds: Sets a timeout on a key.
- KEYS pattern: Returns a list of keys matching a pattern.
For more information, you can refer to the official Redis documentation.
Troubleshooting Redis Installation
If you encounter issues during installation or while running Redis, here are some common troubleshooting steps:
- Check Redis Logs: Review the logs located in
/var/log/redis/
for any error messages that can help diagnose issues. - Verify Port Availability: Ensure that the Redis port (6379) is not being blocked by a firewall or already in use.
- System Resource Limits: If Redis is running out of memory, consider increasing the available system memory or adjusting Redis’ memory configuration in the
redis.conf
file.
Conclusion and Next Steps
Congratulations! You’ve successfully installed Redis on your Ubuntu server. Redis is now ready to be used in your applications. You can start caching data, managing sessions, or exploring other advanced features such as Pub/Sub messaging.
To further improve your Redis skills, you can:
- Explore advanced Redis data types like sorted sets, hashes, and lists.
- Learn about Redis clustering for scalability and high availability.
- Experiment with Redis persistence options for data durability.
If you found this installation guide helpful, feel free to share it with others, and leave a comment with any questions or feedback. Happy coding!
Read Also : How to Install Ansible on Ubuntu?