How to Install Redis on Linux, Mac, and Windows
Posted on September 22, 2024 • 5 min read • 1,055 wordsLearn how to install Redis on Linux, Mac, and Windows with this comprehensive guide. Follow simple steps for each platform, including verification methods, to get Redis up and running quickly. Perfect for developers and system administrators
Redis is a powerful, in-memory key-value store widely used for caching, real-time analytics, and messaging. Its speed and versatility make it a popular choice for developers across multiple platforms. In this guide, we’ll walk you through the process of installing Redis on Linux, Mac, and Windows, ensuring you’re equipped to get started no matter what operating system you’re using.
Redis, short for Remote Dictionary Server, is an open-source, in-memory data structure store. It supports various data types such as strings, hashes, lists, sets, and more. Redis is often used for caching, real-time analytics, and session management, making it a critical component in performance-sensitive applications.
To install Redis on Ubuntu or Debian, follow these steps:
sudo apt update
apt
package manager to install Redis:sudo apt install redis-server
sudo systemctl enable redis-server
sudo systemctl start redis-server
sudo systemctl status redis-server
Redis should now be running on your Ubuntu or Debian system. You can further optimize Redis by editing the configuration file located at /etc/redis/redis.conf
.
If you’re using CentOS or RHEL, the steps are slightly different:
sudo yum update
sudo yum install epel-release
sudo yum install redis
sudo systemctl start redis
sudo systemctl enable redis
sudo systemctl status redis
Redis is now installed and running on CentOS or RHEL.
Installing Redis on MacOS is relatively straightforward using Homebrew, a popular package manager.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install redis
brew services start redis
brew services list
brew services stop redis
Redis will now be running on your Mac machine, and you can interact with it via the terminal.
Unlike Linux and Mac, Redis does not have an official Windows version. However, you can still install Redis on Windows by using Windows Subsystem for Linux (WSL) or by running Redis on Docker.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Install a Linux distribution: From the Microsoft Store, install a Linux distribution like Ubuntu.
Install Redis in the Linux environment: Once installed, open the WSL terminal and run the following commands:
sudo apt update
sudo apt install redis-server
sudo service redis-server start
Redis will now be running within WSL, providing you with a full Linux environment on Windows.
Alternatively, you can run Redis on Windows using Docker:
Install Docker Desktop: Download and install Docker Desktop for Windows from here.
Pull the Redis image: Open PowerShell or Command Prompt and pull the official Redis image:
docker pull redis
docker run --name redis-container -d redis
docker exec -it redis-container redis-cli
After installing Redis on your system, it’s essential to verify that it’s working as expected.
redis-cli
ping
If everything is working correctly, Redis will return:
PONG
set testkey "Hello Redis"
get testkey
Redis should return the value Hello Redis, confirming that your installation is successful.
sudo journalctl -u redis
/etc/redis/redis.conf
) is correctly formatted, especially settings related to bind
and protected-mode
.Check system memory usage. Redis is memory-intensive, and it may crash if your system runs out of memory. You can increase memory limits or reduce Redis’s memory footprint by configuring the maxmemory
directive in the configuration file.
By default, Redis only binds to localhost
for security reasons. To allow remote access:
bind
directive to your server’s IP.protected-mode no
if appropriate, but only do this on trusted networks.Ensure that Redis was installed correctly. If installed via a package manager, check that Redis is in your system’s PATH or manually add it:
export PATH=$PATH:/path/to/redis
Run Redis as a user with the correct permissions, or use sudo for administrative tasks, especially when modifying files like /etc/redis/redis.conf or starting services.
Check for network issues. Redis might be configured to bind to a specific IP address. Verify if Redis is listening on the correct port using:
netstat -tulnp | grep redis
This could indicate a mismatch in Redis version compatibility, especially if running Redis in a cluster. Ensure all instances are running compatible versions of Redis.
These tips should help resolve most common Redis installation and configuration issues.
Whether you’re running Linux, Mac, or Windows, installing Redis is a straightforward process. With Redis installed, you can now explore its robust features, from caching to real-time data processing. For optimal performance, consider configuring Redis based on your use case.