How to Install Redis from Source on Ubuntu 24.04, Debian 12 or AlmaLinux 9
Compile the latest stable Redis from source on Ubuntu 24.04, Debian 12 or AlmaLinux 9 and run it as a systemd service, with notes on licensing and Valkey.
This guide compiles the current stable Redis from source on Ubuntu 24.04 LTS, Debian 12 or AlmaLinux 9 / Rocky Linux 9, installs it under /usr/local, and runs it as a systemd service under its own user with a configuration file and a data directory. It also explains the licence change that matters if you build Redis yourself, and how the same steps apply to Valkey, the BSD-licensed fork.
Before you build: packages, licence and Valkey
Building from source gives you the newest release and control over build options. If you only need a working Redis, a package is less work to keep patched: the distributions ship Redis or Valkey packages, and Redis publishes its own APT repository, described in the official install documentation.
The licence depends on the version you build. According to the Redis source repository:
| Redis version | Licence |
|---|---|
| 7.2.x and earlier | BSD 3-Clause |
| 7.4.x to 7.8.x | RSALv2 or SSPLv1, at your choice |
| 8.0.x and later | RSALv2, SSPLv1 or AGPLv3, at your choice |
For running Redis as the cache or data store of your own application, these licences do not change anything practical. They matter if you offer Redis itself as a service to others or distribute modified versions; read the licence texts in that case.
Valkey is a fork of Redis created by former Redis contributors when the licence changed in 2024. It is a Linux Foundation project and remains under the BSD licence. It builds the same way, as shown near the end of this guide.
Requirements
- A server running Ubuntu 24.04 LTS (22.04 works the same way), Debian 12, or AlmaLinux 9 / Rocky Linux 9. CentOS 7 and 8 are end-of-life; AlmaLinux and Rocky Linux replace them.
- A user with
sudorights. The examples usedeploy. - No other Redis already listening on port 6379.
Step 1: Install the build dependencies
Redis itself needs only a C compiler and libc. The extra development packages below add TLS support and systemd integration, and Tcl is used by the test suite.
On Ubuntu or Debian:
sudo apt update
sudo apt install -y build-essential pkg-config libssl-dev libsystemd-dev tcl wget
On AlmaLinux or Rocky Linux:
sudo dnf install -y gcc make pkgconf-pkg-config openssl-devel systemd-devel tcl wget tar
Step 2: Download the source
The redis-stable tarball always contains the latest stable release:
cd ~
wget https://download.redis.io/redis-stable.tar.gz
tar -xzf redis-stable.tar.gz
cd redis-stable
To build a specific version instead, download its tarball from the releases page of the redis/redis repository on GitHub. Redis publishes digests of its release tarballs in the redis/redis-hashes repository, so you can check the integrity of a download against them.
Step 3: Compile and test
Build with TLS and systemd support, using all CPU cores:
make -j "$(nproc)" BUILD_TLS=yes USE_SYSTEMD=yes
A plain make with no options also works, but the service unit in step 6 relies on the systemd support, so keep USE_SYSTEMD=yes if you follow this guide to the end. This builds the Redis core. Redis 8 can also be built with its bundled modules (JSON, search, time series and others), which needs a much larger toolchain; the per-distribution build pages on redis.io cover that.
Optionally run the test suite. It takes several minutes:
make test
If you change build options later, run make distclean first so that nothing from the previous build is reused.
Step 4: Install the binaries
sudo make install
This copies redis-server, redis-cli, redis-benchmark and the other tools to /usr/local/bin. To install elsewhere, set a prefix, for example sudo make PREFIX=/opt/redis install. Check the result:
redis-server --version
redis-cli --version
At this point you can start Redis in the foreground with redis-server and stop it with Ctrl+C. That is enough for a quick test, but not for a server.
Step 5: Create the user, directories and configuration
Run Redis under an account that has no login shell and owns only its data directory:
sudo useradd --system --home-dir /var/lib/redis --shell /usr/sbin/nologin redis
sudo mkdir -p /etc/redis /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 750 /var/lib/redis
Copy the sample configuration from the source tree:
sudo cp redis.conf /etc/redis/redis.conf
sudo chown root:redis /etc/redis/redis.conf
sudo chmod 640 /etc/redis/redis.conf
Open it in an editor:
sudo nano /etc/redis/redis.conf
Find and set these two directives:
supervised systemd
dir /var/lib/redis
Leave the default bind 127.0.0.1 -::1 and protected-mode yes unless other machines must connect. If they must, bind to a private address, set a password with requirepass (or define ACL users), and restrict port 6379 in your firewall to the clients that need it. Never expose an unauthenticated Redis to the internet.
Step 6: Create the systemd service
Create the unit file:
sudo nano /etc/systemd/system/redis.service
With this content:
[Unit]
Description=Redis data structure server
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
WorkingDirectory=/var/lib/redis
Restart=on-failure
LimitNOFILE=10032
NoNewPrivileges=yes
UMask=0077
[Install]
WantedBy=multi-user.target
Type=notify works together with supervised systemd and the USE_SYSTEMD=yes build option: Redis tells systemd when it is ready. Load the unit and start Redis now and at every boot:
sudo systemctl daemon-reload
sudo systemctl enable --now redis
Step 7: Verify
systemctl status redis
redis-cli ping
The service should be active (running) and the reply PONG. Store and read a value:
redis-cli set greeting hello
redis-cli get greeting
Confirm the version and that Redis is listening only where you expect:
redis-cli info server | grep redis_version
sudo ss -tlnp | grep 6379
If the service fails to start, read its log with sudo journalctl -u redis -e. A start that hangs and then times out usually means the binary was built without USE_SYSTEMD=yes while the unit uses Type=notify. An "Error loading the extension" message means the configuration file refers to a module that was not built; remove the matching loadmodule lines from /etc/redis/redis.conf or build Redis with its modules.
Redis may log a warning that memory overcommit is disabled, which can make background saves fail when memory is low. Enable it permanently:
echo 'vm.overcommit_memory = 1' | sudo tee /etc/sysctl.d/99-redis.conf
sudo sysctl --system
Updating a source build
Nothing updates a source build for you, so watch the Redis release notes for security fixes. To update, download and build the new release as in steps 2 and 3, then:
sudo systemctl stop redis
sudo make install
sudo systemctl start redis
Redis writes its data to /var/lib/redis on shutdown according to the persistence settings in redis.conf, and loads it again on start. Take a copy of that directory before a major version upgrade.
Building Valkey instead
Valkey's build system accepts the same options. Download a release tarball from the valkey-io/valkey repository on GitHub, extract it, and inside the source directory run:
make -j "$(nproc)" BUILD_TLS=yes USE_SYSTEMD=yes
sudo make install
The binaries are named valkey-server and valkey-cli, and make install also creates redis-* symlinks for compatibility. Use the steps above with valkey.conf from the source tree and /usr/local/bin/valkey-server in the unit file.
Frequently asked questions
Should I build from source or install a package?
Use a package unless you need a version or build option that no package provides. Packages are updated by the system's package manager, include a service unit and a dedicated user, and are tested with the distribution. A source build gives you the newest release, at the cost of rebuilding it yourself for every fix.
How do I remove a source build?
Stop and disable the service, run sudo make uninstall in the source directory to remove the binaries from /usr/local/bin, then delete /etc/systemd/system/redis.service, /etc/redis and, if you no longer need the data, /var/lib/redis.
Why does redis-cli say "command not found" after installing?
/usr/local/bin is not on the search path of every environment, in particular under sudo on RHEL-family systems. Run the tool by its full path, /usr/local/bin/redis-cli, or add the directory to your PATH.
Is Valkey a drop-in replacement for Redis?
Valkey's first release, 7.2.5, was based on the last BSD-licensed Redis code, so it is compatible with Redis 7.2 clients, commands and data files. Features added to Redis after the fork, and features added to Valkey since, differ between the two, so check the documentation of the one you run.