This guide shows you how to install Redis Ubuntu 24.04 servers from the official Ubuntu repositories, secure the installation, and tune it for real production workloads. Redis is an in-memory data store used as a cache, a session store, and a lightweight message broker, and it is one of the most common additions to a Linux application stack because it answers requests in microseconds rather than milliseconds. By the end of this tutorial you will have a Redis instance that starts automatically at boot, accepts only local or explicitly trusted connections, requires authentication, persists data safely, and evicts keys gracefully instead of crashing when memory runs out.
Before we start, it is worth understanding what Redis does and does not do. Redis keeps its dataset in RAM, which is why it is so fast, but it also means that memory planning matters far more than it does for a disk-based database such as MySQL. If you give Redis no memory limit, it will happily consume every byte of RAM on the server and eventually trigger the Linux out-of-memory killer. That is why this guide spends as much time on configuration and limits as it does on installation. We will install Redis 7.0, which is the version shipped with Ubuntu 24.04, configure it to run under systemd, enable password authentication, choose a persistence strategy, and verify everything with redis-cli. If you are building a full application stack, you may also want to read our guide on how to install MariaDB on Ubuntu 24.04 for the relational side of the same stack.

Prerequisites
You need a server running Ubuntu 24.04 with a non-root user that has sudo privileges. Redis itself is lightweight and runs comfortably on a small virtual machine, but you should still plan memory carefully: reserve at least 25 percent of system RAM for the operating system and other services, and set the Redis maxmemory limit below the remaining amount. You also need SSH access to the server and a basic familiarity with editing files in a terminal editor such as nano. No other software is required, because Redis ships everything it needs in a single package, including the redis-server daemon and the redis-cli command-line client. If you plan to let another server reach Redis over the network, decide that now and note the application server’s IP address, because the secure default is to listen only on localhost and we will only open that up deliberately.
How to Install Redis Ubuntu 24.04 from APT
Start by refreshing the package index and installing the redis-server package. Ubuntu 24.04 includes Redis 7.0 in its main repositories, so no third-party repository is needed for a standard installation. Using the distribution package has a real advantage: security updates arrive through the normal apt workflow, and the package ships a systemd service file and a sensible default configuration.
sudo apt update
sudo apt install redis-server -y
redis-server --version
Once the package is installed, check that the service is running. The package enables the service automatically on most systems, but verifying this explicitly avoids a confusing failure later when you test the connection. The output of the status command should show the service as active and running, with the main process listed as redis-server.
sudo systemctl status redis-server
sudo systemctl enable redis-server
Test the installation with redis-cli. The ping command should return PONG, which confirms that the server is listening and responding. At this point the server still uses the default configuration, so do not stop here: the next steps lock it down and make it suitable for production.
redis-cli ping
Install Redis Ubuntu 24.04: Secure the Configuration
The main configuration file is /etc/redis/redis.conf. Three settings deserve your attention first: supervised, bind, and protected-mode. The supervised directive tells Redis how it is managed by the init system, and on Ubuntu it must be set to systemd so that Redis can signal readiness to systemd correctly and shut down cleanly. The bind directive controls which network interfaces Redis listens on, and protected-mode is a safety net that refuses connections from outside localhost when no password is set. Open the file with nano and make the following changes.
sudo nano /etc/redis/redis.conf
supervised systemd
bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
Next, set a strong password. Find the requirepass directive, which is commented out by default, and replace it with a long random password. Generate one with openssl rather than inventing something memorable, and store it in your password manager, because you will need it every time an application or redis-cli connects. While you are in the file, also set a memory limit and an eviction policy so that Redis degrades gracefully under pressure instead of failing outright.
requirepass YourStrongPasswordHere
maxmemory 256mb
maxmemory-policy allkeys-lru
The allkeys-lru policy evicts the least recently used keys across the whole dataset when the limit is reached, which is the right default for a cache. If Redis is your primary data store rather than a cache, consider noeviction instead, but understand that writes will then fail with an out-of-memory error when the limit is reached, which is only acceptable if your application handles that case. Save the file, restart the service, and confirm that authentication now works: a bare ping should return an error, and an authenticated ping should return PONG.
sudo systemctl restart redis-server
redis-cli ping
redis-cli -a YourStrongPasswordHere ping
Note that passing a password with the -a flag prints a warning about using a password on the command line, because it may be visible in the shell history or process list. For interactive testing that is acceptable, but applications should pass credentials through environment variables or a configuration file with restricted permissions, never through command-line arguments in a production script.
Persistence: RDB Snapshots Versus AOF Logs
Redis offers two persistence mechanisms, and the choice depends on how much data loss you can tolerate. RDB persistence writes a point-in-time snapshot of the dataset to disk at intervals you define, for example after 3600 seconds if at least one key changed. Snapshots are compact and fast to reload, which makes them excellent for backups and disaster recovery, but you can lose everything written since the last snapshot. AOF persistence, by contrast, logs every write operation and can be configured to fsync on every write, every second, or on operating system schedule. Appending every second is the usual compromise: you lose at most one second of writes, and performance stays close to snapshot-only mode.
For a cache, RDB snapshots alone are usually enough, because the data can always be rebuilt from the primary database. For a session store or a queue where losing a minute of data hurts, enable AOF as well. You can enable both at once: Redis will load the AOF file on startup when both are present, because it is the more complete record. Edit the configuration as follows, then restart the service.
save 3600 1 300 100 60 10000
appendonly yes
appendfsync everysec
dir /var/lib/redis
Make sure the data directory is owned by the redis user and has enough free disk space for both the snapshot and the append-only file. A useful habit is to check persistence status after any configuration change with the INFO persistence section, which reports the last successful save time, the current AOF size, and whether any background save is in progress. If you are setting up the rest of the stack at the same time, our LAMP stack guide for Ubuntu 24.04 covers the web server and PHP side that typically sits in front of Redis.
Firewall and Remote Access Notes
By default this guide binds Redis to localhost, which means no firewall rule is needed and no other machine can reach it. That is the configuration you want for the overwhelming majority of single-server deployments, where the application and Redis run on the same host. If you genuinely need remote access, bind the specific private IP address of the server instead of 0.0.0.0, keep requirepass enabled, and restrict access with UFW to only the application servers that need it. Never expose port 6379 to the public internet: unauthenticated or weakly authenticated Redis instances are routinely discovered and abused for data theft and cryptomining. The official Redis documentation on installing Redis on Ubuntu reinforces the same point about binding and protected mode.
sudo ufw allow from 10.0.0.5 to any port 6379 proto tcp
sudo ufw status numbered
Replace the example address with your real application server address. After adding the rule, test connectivity from the application server with redis-cli using the -h flag and confirm that a connection from any other address is refused. Also verify that Redis is still listening only where you expect by inspecting listening sockets on the server.
sudo ss -tlnp | grep 6379
Troubleshooting
The most common failure after installation is connection refused. This almost always means the service is not running, or it is bound to a different interface than the one you are connecting to. Check the service status first, then the log file at /var/log/redis/redis-server.log, then the listening sockets. If you changed supervised to systemd but forgot to restart, the service may be running under the old configuration, so a restart after every configuration edit is essential.
Authentication errors are the next most frequent problem. The error message NOAUTH Authentication required means the client connected without a password, while WRONGPASS invalid username-password pair means the password does not match requirepass. Both are fixed by correcting the client configuration, not by weakening the server. If your application framework has a separate Redis password setting, update it there and restart the application, because a stale cached configuration is a common cause of a sudden authentication failure after a password rotation.
Out-of-memory errors deserve a different response. When maxmemory is reached with the noeviction policy, writes fail but reads keep working, which can look like a mysterious application bug. Check memory usage with INFO memory, look at used_memory_human and the eviction counters, and either raise maxmemory if the server has headroom or switch to an eviction policy that matches your workload. If the server itself is running out of RAM, Redis is usually the victim, not the cause: check total system memory usage before blaming the cache, and consider enabling swap only as a last resort, since swapping an in-memory store destroys its performance advantage.
Conclusion
You now have a Redis installation on Ubuntu 24.04 that is secured with authentication, bound to trusted interfaces, protected by a memory limit and eviction policy, and configured with persistence that matches your tolerance for data loss. The habits that matter most going forward are boring ones: restart the service after every configuration change, verify with redis-cli rather than assuming, monitor memory usage before it becomes an emergency, and never expose the Redis port to the internet. With those habits in place, Redis will quietly do what it does best: make your application feel instant.