Â
Redis is an open-source in-memory data structure storage known for its excellent speed and scalability. This guide provides a comprehensive overview of installing and setting up Redis on various operating systems, including Linux, Windows, and macOS.
You’ll learn how to add a Redis repository, install software, Manage Redis servers, and connect to them using the Redis CLI, whether you’re developing storage-hungry applications. Real-time analysis or data storage This guide will help you with the knowledge to get started with Redis.
Redis was originally developed as a key-value store, but it has evolved into a versatile tool capable of handling many data types and use cases. It is particularly popular for its high performance, as it stores data in memory rather than on disk, allowing for extremely fast read and write operations. This makes Redis an excellent choice for applications that require quick access to frequently changing data, such as real-time analytics, caching, and session management.
Redis’s flexibility allows developers to implement various data structures efficiently, making it suitable for applications in numerous domains, including web development, gaming, IoT, and big data. Its open-source nature means it is freely available and has a large community contributing to its development, ensuring continuous improvements and a wealth of resources.
Â
Prerequisites
Â
Before you begin the installation and setup process, ensure that you meet the following prerequisites:
- Basic Knowledge of Command Line: Familiarity with command line operations will help you navigate the installation process smoothly
- Access to a Computer: You should have a computer running one of the following operating systems:
- Internet Connection: A stable internet connection is necessary to download Redis and any additional tools
- Administrator Privileges: Ensure you have the necessary permissions to install software on your computer, especially for Windows and Linux users
Â
Step-by-Step Guide for Installation
Â
How to Install Redis on Linux
Most major Linux distributions provide packages for Redis, making installation straightforward. Below are detailed steps for installing Redis on Ubuntu/Debian and Red Hat/Rocky Linux.
Â
Install on Ubuntu/Debian
- Install Required Packages: Before installing Redis, you may need to install some prerequisite packages. Open your terminal and run the following command:
- Add the Redis Repository: You must add the official Redis repository to your system’s package manager. Execute the following commands:
- Update Package List and Install Redis: Now, update your package list and install Redis:
- Start Redis Service: Redis should start automatically after installation. If it doesn’t, you can start it manually:
- Enable Redis to Start on Boot: To ensure that Redis starts automatically on system boot, run:
Â
sudo apt-get install lsb-release curl gpg
Â
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
Â
sudo apt-get update
sudo apt-get install redis
Â
sudo systemctl start redis-server
Â
sudo systemctl enable redis-server
Â
Â
Install on Red Hat/Rocky
- Install Redis: For Red Hat or Rocky Linux, simply run:
- Start and Enable Redis: Start Redis and enable it to restart at boot:
Â
sudo systemctl enable redis
sudo systemctl start redis
Â
Â
Install on Ubuntu using Snap (OPTIONAL)
To install Redis using Snap, follow these steps:
- Update Snap: Open your terminal and run:
- Install Redis Tools and Redis:
- Manage Redis with Snap: Redis will start automatically but won’t restart at boot time. Use these commands to manage Redis:
- Enable Redis to Start on Boot: To enable Redis to restart at boot, run:
Â
sudo apt install redis-tools # for redis-cli
sudo snap install redis
Â
sudo snap start redis
sudo snap stop redis
sudo snap restart redis
sudo snap services redis
Â
sudo systemctl enable redis
Â
Â
Starting and Stopping Redis in the Background
To manage the Redis server as a background process, use the systemctl command:
- Start Redis:
- Stop Redis:
sudo systemctl start redis-server # Use redis or redis-server depending on the platform
Â
sudo systemctl stop redis-server # Use redis or redis-server depending on the platform
Â
Â
Test Redis Installation
Once Redis is running, you can test the connection using the Redis CLI:
- Launch Redis CLI: Open your terminal and enter:
- Test the Connection: In the Redis CLI, test the connection by typing:
Â
Â
If Redis is functioning correctly, you should receive a response:
Â
If the message appears, the installation is successful.
Â
Installing Redis on Windows
Â
While Redis is not officially supported on Windows, you can install it for development purposes using Windows Subsystem for Linux (WSL). Follow these steps:
Â
Enable WSL2
- Check Windows Version: Ensure you are running Windows 10 version 2004 or higher or Windows 11
- Install or Enable WSL: Follow Microsoft’s detailed instructions for installing WSL. This guide assumes Ubuntu is the default Linux distribution
Â
Install Redis
Once WSL is running with Ubuntu, follow the steps for Ubuntu/Debian to install Redis:
- Add the Redis Repository:
- Update and Install Redis:
- Start the Redis Server:
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
Â
sudo apt-get update
sudo apt-get install redis
Â
sudo service redis-server start
Â
Â
Test Redis Installation
Just as with Linux, use the Redis CLI to test your installation:
- Launch Redis CLI:
- Test the Connection:
- You should see:
Â
Â
Â
If the message appears, the installation is successful.
Â
Installing Redis on macOS
Â
If you’re using macOS, the easiest way to install Redis is through Homebrew. Here’s how:
Â
Prerequisites
First, make sure you have Homebrew installed. Install Homebrew on macOS (If you haven’t Installed it already)
Open your terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Â
Follow the on-screen instructions to complete the installation. To check if Homebrew was installed successfully, run:
Â
Install Redis
Once Homebrew is installed, you can install Redis with the following command:
Â
Start Redis
- After installation, you can start Redis using:
- This command sets Redis to start automatically at login. If you prefer to start it manually, use:
Â
brew services start redis
Â
Â
Test Redis
- You can test if Redis is running by opening another Terminal window and typing:
- This opens the Redis command-line interface. You can then test the connection by typing:
- You should see:
Â
Â
Â
If the message appears, the installation is successful.
Â
Conclusion
Â
In this tutorial, we covered the installation and setup of Redis on various operating systems, including Windows, macOS, and Linux. We also explored how to connect to Redis and test its functionality. Redis’s versatility and performance make it a valuable tool for developers looking to manage data efficiently in their applications.
As you continue your journey with Redis, consider exploring its extensive documentation and community resources to unlock its full potential.
Â
Â
Shittu Olumide is a software engineer and technical writer passionate about leveraging cutting-edge technologies to craft compelling narratives, with a keen eye for detail and a knack for simplifying complex concepts. You can also find Shittu on Twitter.