Host Your Own AI Agent with OpenClaw - Free 1-Click Setup!

Install and Configure Redis on Ubuntu: A Complete Setup Guide

Getting Redis up and running on Ubuntu isn’t complicated, but there’s a difference between just installing it and setting it up properly. A solid redis ubuntu installation means binding to the right interfaces, turning on authentication, and figuring out how you want to handle persistence. This guide walks through everything—from the initial install to a configuration you can actually use in production. 

What Redis Is and Why It Works Well on Ubuntu

Redis is an open-source, in-memory data store. People use it as a redis cache, a message broker, or even a database. Since it keeps everything in RAM instead of writing to disk, reads and writes happen incredibly fast—we’re talking microseconds. That makes the redis server a great fit for things like session management, real-time leaderboards, rate limiting, or caching results from database queries. 

Ubuntu is one of the most common Linux distributions in server environments, and Redis has solid support for it through the official package repositories. Together, they make a reliable stack whether you’re building something small or running a high-traffic production system. 

Redis vs Memcached: What Actually Matters

The redis vs memcached debate shows up a lot when teams are picking a caching solution. Both live in memory, but they’re built for different things. Redis supports way more data structures, has persistence built in, handles replication and clustering natively, and includes pub/sub messaging. Redis performance stays strong across all these features without getting complicated. 

Memcached is intentionally stripped down. It only stores plain string values, has no persistence, and doesn’t do replication. If you need pure, straightforward caching with predictable access patterns, Memcached is fast and lightweight. But for anything beyond that, Redis gives you more flexibility and room to grow. 

Redis Data Types and When to Use Them

Redis data types go way beyond simple key-value strings. The most common ones include strings, lists, sets, sorted sets, hashes, and bitmaps. Each one fits naturally with certain use cases. A sorted set, for instance, is perfect for a leaderboard because it automatically keeps members ranked by score. A hash works well for storing user session data as a collection of fields. Lists support queue and stack patterns that are useful for background job processing. 

Redis commands for working with each type are clean and consistent. SET and GET handle strings, LPUSH and LRANGE manage lists, ZADD and ZRANGE operate on sorted sets, HSET and HGETALL work with hashes. Knowing which type fits your data model is really the foundation of using Redis effectively. 

What You Need Before Installing Redis

Before running any install commands, make sure a few things are in place. 

System Requirements and Ubuntu Version

Redis runs on any modern Ubuntu version. This guide focuses on Ubuntu 22.04 LTS and Ubuntu 24.04 LTS, which are the current long-term support releases you’ll see most often in production redis ubuntu setups. The redis setup needs a server with at least 512 MB of RAM, though 1 GB or more is better for production workloads. You’ll also need sudo privileges on the machine. 

Connecting via SSH or Browser Terminal

To interact with your redis server, you need terminal access to the Ubuntu machine. For a VPS, this usually means connecting via SSH from your local machine with something like ssh username@your-server-ip. A lot of hosting providers also offer a browser-based terminal right in their control panel if you’d rather not set up SSH locally. Either way works fine for everything that follows. 

How to Install Redis on Ubuntu VPS

Once you’ve confirmed terminal access, you’re ready to install redis ubuntu. The steps below take you from a clean server to a fully configured and verified Redis instance. 

Step 1: Install the Redis Server Package

Ubuntu’s default package repositories include Redis, so the install redis ubuntu process starts with a standard apt command. First, update the package index so you’re pulling the latest available version: 

sudo apt update

Then install the Redis server package: 

sudo apt install redis-server -y

Once installation finishes, the Redis service starts automatically. You can confirm it’s active with: 

sudo systemctl status redis-server

You should see an active (running) status in the output. Redis is now installed, but the default configuration isn’t suitable for production use without some changes. 

Step 2: Configure Redis for Your Environment

The main redis configuration file is located at /etc/redis/redis.conf. Open it with a text editor like nano: 

sudo nano /etc/redis/redis.conf

The first important setting is supervised. By default it’s set to no. Since Ubuntu uses systemd to manage services, change this to systemd: 

supervised systemd

This tells Redis to integrate properly with systemd, which means the service will restart correctly after failures and behave as expected during system reboots. 

The second setting to look at is maxmemory. If you’re using Redis as a cache, set a memory limit to prevent it from eating up all your available RAM. Add or update this line with a value that makes sense for your server: 

maxmemory 256mb

Pair it with a maxmemory-policy directive to tell Redis what to do when it hits that limit. For a cache, allkeys-lru is a sensible default—it evicts the least recently used keys to make room for new ones: 

maxmemory-policy allkeys-lru

Save the file in nano with Ctrl+O, hit Enter to confirm, and exit with Ctrl+X. Restart Redis to apply the changes: 

sudo systemctl restart redis-server

Step 3: Enable Password Authentication

By default, Redis accepts connections without any credentials. In a production environment, redis authentication is essential. To set a password, go back to the configuration file: 

sudo nano /etc/redis/redis.conf

Find the line that says requirepass and either uncomment it or add it if it’s not there. Replace the placeholder with a strong password: 

requirepass YourStrongPasswordHere

Save and exit, then restart the service: 

sudo systemctl restart redis-server

From this point forward, any client connecting to the redis configuration will need to authenticate before issuing commands. In the Redis CLI, you authenticate with: 

AUTH YourStrongPasswordHere

For application connections, the password is typically passed through the connection string or client library configuration. 

Step 4: Verify Redis Is Running Correctly

With authentication in place, test the installation using the built-in Redis CLI. Open it with: 

redis-cli

If password authentication is enabled, authenticate right after opening the CLI: 

AUTH YourStrongPasswordHere

Then run a basic ping command to confirm the server is responding: 

PING

The server should return PONG. You can also run a quick redis commands test by setting and retrieving a key: 

SET testkey "hello"
GET testkey

The output should return hello, confirming that reads and writes are working correctly. Redis performance at this stage can be benchmarked using the built-in tool redis-benchmark if you want baseline numbers for your server. 

How to Secure Redis on Ubuntu

Installation and basic configuration are done. The next layer is security hardening. 

Binding Redis to Specific IP Addresses

By default, Redis listens on all available network interfaces, which unnecessarily exposes it if your server has a public IP. In the redis configuration file, find the bind directive: 

sudo nano /etc/redis/redis.conf

Locate the line starting with bind and update it to include only the interfaces Redis should listen on. For a setup where only the local machine and a specific internal IP need access, the directive looks like this: 

bind 127.0.0.1 192.168.1.100

Replace 192.168.1.100 with your actual internal IP address. This limits which interfaces the redis server accepts connections on. After saving and restarting, Redis will no longer accept connections from any other address, which significantly reduces your attack surface. 

Using Redis Sentinel for High Availability

Redis sentinel is the built-in solution for monitoring, automatic failover, and notifications in Redis deployments. A Sentinel setup involves running one or more Sentinel processes that monitor the primary Redis instance. If the primary becomes unavailable, Sentinel coordinates a promotion of one of the replicas to take over automatically. 

This is different from a redis cluster, which focuses on horizontal data partitioning across multiple nodes. Sentinel handles high availability for a single dataset across a primary and its replicas. For most VPS deployments, Sentinel is the right choice. Setting up Sentinel requires at least three Sentinel instances to reach quorum reliably, typically running on separate servers or availability zones. 

Redis Persistence and Backup Options

By default, Redis stores data in memory, which means a restart wipes everything unless persistence is configured. Two main options exist. 

RDB Snapshots vs AOF Logging

RDB (Redis Database) snapshots write the entire dataset to disk at configurable intervals. This is the default redis persistence mechanism. The snapshot file is compact and easy to move, making it well suited for backups. The downside is that any data written since the last snapshot gets lost in a crash. 

AOF (Append Only File) logging records every write operation to a log file. On restart, Redis replays the log to reconstruct the dataset. This approach loses far less data in a failure scenario—typically at most one second of writes depending on the fsync setting. The trade-off is a larger file and slightly more I/O overhead. 

For production deployments, enabling both is a common pattern in the redis cluster ecosystem. Redis uses the AOF for recovery when both are enabled, while the RDB provides a compact periodic backup suitable for offsite storage. Configure both in /etc/redis/redis.conf by setting appendonly yes for AOF and adjusting the save directives for RDB intervals. 

Running Redis with Docker

For development environments or containerized production setups, the redis docker approach is often more convenient than a direct installation. Pulling and running the official Redis image requires only two commands: 

docker pull redis
docker run --name my-redis -d -p 6379:6379 redis

This runs Redis in a detached container with the default port exposed. To run with a password and persist data to the host machine, extend the command with environment variables and a volume mount: 

docker run --name my-redis -d -p 6379:6379 -v /your/local/path:/data redis redis-server --requirepass YourStrongPasswordHere --appendonly yes 

The redis setup via Docker isolates the process cleanly and makes version upgrades straightforward. For production Docker deployments, using a Docker Compose file with defined resource limits and a restart policy is more maintainable. 

FAQ: Install Redis on Ubuntu

How do I install Redis on Ubuntu 22.04?

Run sudo apt update followed by sudo apt install redis-server -y. The service starts automatically after install redis ubuntu completes. Confirm it’s running with sudo systemctl status redis-server, then move on to configuring the supervised, maxmemory, and requirepass settings in /etc/redis/redis.conf. 

How do I check if Redis is running on Ubuntu? 

Use sudo systemctl status redis-server to check the service status. To confirm the redis server is accepting connections, open the redis commands interface with redis-cli and run PING. A PONG response confirms everything is working. 

How do I set a Redis password on Ubuntu? 

Open /etc/redis/redis.conf with sudo nano /etc/redis/redis.conf, locate or add the requirepass directive, and set a strong password. Save the file and restart the service with sudo systemctl restart redis-server. Redis authentication is then required for all new connections. 

What is the difference between Redis and Memcached? 

The main redis vs memcached distinction is in capability. Redis supports multiple data structures, persistence, replication, pub/sub, and clustering. Memcached supports only plain string values with no persistence or replication. Redis is the better choice for most modern applications. Memcached still makes sense for simple, high-volume string caching where its lower complexity is an advantage. 

Scroll to Top