Sports

Installing Redis on Ubuntu: A Complete Step-by-Step Guide

By 4 min read 398 views
Featured image for Installing Redis on Ubuntu: A Complete Step-by-Step Guide

Installing Redis on Ubuntu

Redis is an in-memory data store commonly used as a cache, message broker, or session store. On Ubuntu, the most reliable path is to add the official Redis PPA and install from there, which gives you a more recent version than the default Ubuntu repositories. The process covers adding the repository, installing the package, enabling the service, and performing a minimal security check.

More from this site

Keep reading the latest coverage

Browse latest →

Prerequisites

  • An Ubuntu server (22.04 LTS or 24.04 LTS are well supported).
  • A non-root user with sudo privileges.
  • A stable internet connection to fetch packages from the Redis repository.

Step 1: Update System Packages

Before adding new repositories, refresh your local package index to avoid dependency conflicts.

sudo apt update && sudo apt upgrade -y

Step 2: Add the Redis PPA

The Redis maintainers provide an official APT repository that tracks stable releases more closely than Ubuntu's own packages.

sudo apt install software-properties-common -y sudo add-apt-repository ppa:redis/ppa

Press Enter when prompted to accept the repository. Once added, update again so apt can see the new packages.

sudo apt update

Step 3: Install Redis

With the PPA enabled, install the redis-server package. This pulls in the Redis server, the redis-cli client, and any required dependencies in one step.

sudo apt install redis-server -y

Step 4: Verify the Installation

After installation, confirm that Redis is running and check the version to ensure the correct package was installed.

redis-cli ping redis-server --version

A response of PONG means the server is accepting connections. If you see a connection refused error, the service may not have started correctly; check the next step.

Step 5: Manage the Redis Service

Redis is managed by systemd on modern Ubuntu. Use these commands to control it.

  • Check status: sudo systemctl status redis-server
  • Enable at boot: sudo systemctl enable redis-server
  • Restart after config changes: sudo systemctl restart redis-server

Step 6: Basic Security Hardening

A freshly installed Redis instance is not secure by default. At a minimum, bind it to localhost and set a password.

Bind to localhost

Open the configuration file:

sudo nano /etc/redis/redis.conf

Find the bind directive and ensure it reads:

bind 127.0.0.1

Set a Password

Locate the requirepass line, uncomment it, and set a strong password:

requirepass your_strong_password_here

Save the file and restart Redis for the changes to take effect.

sudo systemctl restart redis-server

Step 7: Configure Firewall Rules (Optional)

If you plan to allow remote connections, open port 6379 in the firewall. For local-only use, leave the port closed.

sudo ufw allow redis

Step 8: Test Basic Operations

Use redis-cli to confirm read and write operations work as expected.

redis-cli SET testkey "hello redis" GET testkey exit

You should see hello redis returned. This confirms both the server and the client are functioning correctly.

Troubleshooting Common Issues

  • Connection refused: Check that the service is running with sudo systemctl status redis-server and that the bind address matches how you are connecting.
  • Permission denied: Ensure your user is in the sudo group and that you are prefixing commands with sudo where required.
  • Outdated version: Run apt-cache policy redis-server to confirm you are getting the PPA version and not the Ubuntu default.

Uninstalling Redis

If you need to remove Redis later, stop the service, purge the package, and delete the data directory.

sudo systemctl stop redis-server sudo apt purge redis-server -y sudo rm -rf /var/lib/redis /etc/redis/redis.conf

Final Notes

Installing Redis on Ubuntu via the official PPA gives you a predictable path to a stable, up-to-date release. The steps above cover the minimal setup needed for local development or production use, including service management and basic security. For production deployments, consider enabling persistence, tuning memory limits with maxmemory, and restricting network access further based on your architecture.

Editor's pick

Keep exploring our latest stories

Fresh reads, picked daily.

Browse latest
Share: