Estimated reading time: 3 minutes
If you’re looking to harness the power of Redis on Ubuntu, you’re in the right place. In this guide, I’ll walk you through installing Redis on Ubuntu 24.04 with secure settings to ensure smooth and efficient use. Redis installation on Linux is straightforward, and following these steps will have you up and running in no time.
Step 1: Preparing for Redis Installation
Before installing Redis, start by updating the package index to ensure all software sources are up-to-date. Run:
sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
This prepares your system to fetch and install the latest Redis package. Updating the package index ensures you don’t encounter compatibility issues during the installation.
Read also: Install Redis on Ubuntu Manually
Step 2: Installing Redis
Now, it’s time to install Redis. Use the command below to download and install Redis directly from Ubuntu’s official package repository:
sudo apt-get install redis
After installing Redis, you can confirm the version by typing:
redis-server --version
This command will display the installed version, which should be ready to use immediately.
Step 3: Configuring Redis for Optimal Performance
Redis’s default settings work well, but a few configuration adjustments will help secure and optimize it. Open the main configuration file with:
sudo nano /etc/redis/redis.conf
In the file, set Redis to run in the background by enabling the “daemonize” directive:
daemonize yes
Redis also defaults to 127.0.0.1
, the localhost, which prevents outside access. This is a secure setup for development environments but can be modified for specific networking needs.
Step 4: Enabling and Starting Redis
To make sure Redis starts automatically with your system, enable it by running:
sudo systemctl enable redis-server.service
Then, start the Redis service:
sudo systemctl start redis
To check the Redis status and confirm it’s running, use:
sudo systemctl status redis
If Redis is active, it’s ready to accept connections.
Step 5: Securing Redis with Authentication
By default, Redis doesn’t require a password, which can be risky in production environments. To enable a password, open the configuration file again:
sudo nano /etc/redis/redis.conf
Locate the requirepass
directive, uncomment it, and set a strong password:
requirepass YourStrongPassword
Save the changes and restart Redis:
sudo systemctl restart redis
Now, when accessing Redis, you’ll need to authenticate. Try logging in with the redis-cli
command and use the auth
command to authenticate with your password.
Final Thoughts on Using Redis with Ubuntu
Now that Redis is installed and configured, it’s ready to boost your application’s speed and performance. Whether you’re using it for caching, message brokering, or session management, Redis on Ubuntu offers powerful support for high-speed data management. So go ahead and put Redis to work on your applications!