Hey there, you might have heard about redis and what it does, and that's the reason you are here. So If I keep it short, Redis is a high-performance, in-memory data store. It functions primarily as a cache or a quick-response database.
In this guide, I will be showing you how you can self host in your Ubuntu server.So let's get going.
Prerequisite
To proceed with this guide, you need to have an Ubuntu Server (Obviously). Other then that, you do not need anything else.
Steps
Step 1- Update Your System and Install Prerequisites
First things first: make sure your system is up to date. Its better to do it, to avoid any package conflicts in future
Run this to update your package list:
sudo apt-get update
sudo apt-get upgrade -y
Now, install some essentials we'll need for adding the Redis repository. These include tools for handling keys and releases:
sudo apt-get install lsb-release curl gpg
Step 2: Add the Official Redis Repository
Redis has its own package repository, which is better than using Ubuntu's default one because it gives you the most recent version. Here's how to set it up.
Download and add the Redis GPG key:
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
Set permissions on that key file (644 is standard for read access):
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
Add the repository to your sources list. This line points to the Redis packages tailored to your Ubuntu version (like "jammy" for 22.04):
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
Update your package list again to include the new repo:
sudo apt-get update
Step 3: Install Redis
sudo apt-get install redis
This should pull in the latest version. Once it's done, you can check the version with redis-server --version
to confirm everything's good.
Step 4: Start and Enable the Redis Service
Redis runs as a service, so let's get it fired up and make sure it starts on boot.
Enable it:
sudo systemctl enable redis-server
Start the service:
sudo systemctl start redis-server
To verify it's running, check the status:
sudo systemctl status redis-server
You should see something saying it's active (running). If not, there might be an error—feel free to drop the output in the comments if you run into issues!
Step 5: Configure Redis for Remote Connections
By default, Redis only listens on localhost (127.0.0.1), which is great for security but not if you need to connect from another machine. We'll tweak the config file to allow remote access, disable protected mode, and add a password for safety.
Open the config file with your favorite editor (I like nano):
sudo nano /etc/redis/redis.conf
Make these changes:
- Find the line that says
bind 127.0.0.1
(it shouldn't have a # or leading space). Change it tobind 0.0.0.0
. This tells Redis to listen on all interfaces. - Look for
protected-mode yes
and switch it toprotected-mode no
. This disables the default protection that blocks remote access. - Add or uncomment the line for a password:
requirepass your-strong-password-here
. Replace "your-strong-password-here" with something secure—don't use a weak one, especially if this is exposed to the internet!
Save and exit (in nano, that's Ctrl+O, Enter, Ctrl+X).
Restart Redis to apply the changes:
sudo systemctl restart redis
Check the status again to ensure it's back up:
sudo systemctl status redis
And thats it, your redis server is up and running and ready to be connected.
Show me the code
# Update system and install prerequisites
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install lsb-release curl gpg
# Add Redis GPG key and repository
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
# Install Redis
sudo apt-get install redis
# Enable and start the service
sudo systemctl enable redis-server
sudo systemctl start redis-server
Configure for Remote Connections
- Open the config file:
sudo nano /etc/redis/redis.conf
(or use your preferred editor). - Find the line
bind 127.0.0.1
(no leading # or space) and change it tobind 0.0.0.0
. - Find
protected-mode yes
and change it toprotected-mode no
. - Add or edit the line to set a password:
requirepass <your-strong-password>
(replace with a secure password). - Save and exit the editor.
# Restart and check status
sudo systemctl restart redis-server
sudo systemctl status redis-server
I hope you have found this article helpful, If you have any issues, just ask me in the comments.