Getting Started with Redis: Installation and Setup Guide
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.
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:
- Windows
- macOS
- Linux
- 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 yum install redis
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 update
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:
redis-cli
ping
If Redis is functioning correctly, you should receive a response:
PONG
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:
redis-cli
ping
PONG
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:
brew --version
Install Redis
Once Homebrew is installed, you can install Redis with the following command:
brew install redis
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:
redis-server
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:
redis-cli
ping
PONG
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.