Estimated reading time: 3 minutes
Installing Redis manually on Ubuntu lets you work with the latest Redis version and gives you full control over the build process. Here’s a step-by-step guide on how to download, build, and install Redis manually on Ubuntu.
Table of contents
- Step 1: Preparing Your System
- Step 2: Downloading Redis
- Step 3: Extracting the Redis Files
- Step 4: Building Redis from Source
- Step 5: Installing Redis
- Step 6: Configuring Redis as a Background Service
- Step 7: Starting Redis Manually after installing
- Step 8: Setting Up Redis as a System Service
- Conclusion and Final Thoughts
- Further reading
Step 1: Preparing Your System
Before downloading Redis, update your system’s package list. This ensures you have the latest dependencies needed for building Redis from source. Run:
sudo apt update
sudo apt install build-essential tcl
The build-essential
package includes compilers and libraries needed for Redis, while tcl
is required to run the Redis test suite.
Step 2: Downloading Redis
Download Redis directly using wget
. In your terminal, run:
wget http://download.redis.io/redis-stable.tar.gz
This command downloads the latest stable release of Redis as a compressed .tar.gz
file.
Step 3: Extracting the Redis Files
Now, extract the downloaded file using:
tar xzf redis-stable.tar.gz
This creates a directory called redis-stable
containing the source files.
Step 4: Building Redis from Source
Next, enter the Redis directory and start the build process:
cd redis-stable
make
The make
command compiles the Redis source code into executable binaries. Once completed, it’s a good idea to run the Redis test suite to ensure everything is working correctly:
make test
The tests might take a few minutes to complete, and this step verifies that Redis is built correctly.
Step 5: Installing Redis
If the tests pass, install Redis binaries by running:
sudo make install
This command installs Redis binaries in /usr/local/bin
, making them available globally on your system.
Step 6: Configuring Redis as a Background Service
To run Redis as a background service, create a configuration directory and copy the Redis configuration file to it:
sudo mkdir /etc/redis
sudo cp redis.conf /etc/redis
Now, open the configuration file to modify some settings:
sudo nano /etc/redis/redis.conf
Enable Daemon Mode
Find the daemonize
line and set it to yes
so Redis runs in the background.
daemonize yes
Set Protected Mode
This mode prevents unauthorized access by default and is suitable for production.
Once done, save and exit the editor.
Step 7: Starting Redis Manually after installing
You can now start Redis manually using:
redis-server /etc/redis/redis.conf
This command launches Redis with the specified configuration file. If you configured it to run as a daemon, Redis will continue running in the background.
Step 8: Setting Up Redis as a System Service
To make Redis start automatically on boot, you can set it up as a systemd service. Create a new service file:
sudo nano /etc/systemd/system/redis.service
Paste the following into the file:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=root
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
Save and close the file, then enable and start the Redis service with:
sudo systemctl enable redis
sudo systemctl start redis
To check the status of Redis, you can use:
sudo systemctl status redis
Conclusion and Final Thoughts
Installing Redis manually on Ubuntu gives you control over the build and configuration, ensuring you’re using the latest stable version. By following these steps, Redis is now set up to run efficiently as a background service.