Redis is key-value storage known for its flexibility, performance, and wide language support.
This tutorial will show you how you can install and set up Redis on your Ubuntu 18.04 machine from the Command Line, in just a few steps!.
Table of Contents
Step 1: Install Redis from Ubuntu sources
Since the official Ubuntu repository has source links to Redis (redis-server), we can install them using the
apt package manager itself.
As always, update your system critical packages before installing an external package.
sudo apt update sudo apt install redis-server
Now, Redis will have been installed in your system. Let us verify our installation now.
Step 2: Verify Redis Installation
If our installation has completed successfully, a service called
redis.service would have automatically started to run.
Let us check if the Redis service is active or not, using:
sudo systemctl status redis
If the service is indeed running, you will see an output similar to the screenshot below.
Step 3: Configure Redis
Before using Redis, there are some configuration tweaks we need to do from the default config.
We will make our changes in the Redis Configuration File, which is located at
Open this file using a text editor (vi, nano, etc), using
sudo, since we need to edit the file.
root@ubuntu:~ # sudo vi /etc/redis/redis.conf
Go to the line which configures the supervised configuration option.
By default, the option would be no.
Change this to systemd, since we have an Ubuntu System, and we need to supervise this server.
After changing this option, there are no further changes to be made. So exit the editor after saving changes.
Now, to apply our configuration change on redis-server, we need to restart the already running service. (We can also reboot)
systemctl to restart redis.service.
sudo systemctl restart redis.service
If this returns to the Shell prompt, we have successfully applied the configuration change to our Redis server!
Step 4: Test Redis
Now, just to make sure, let us check the status of redis again.
sudo systemctl status redis
We should get the same output as before, indicating that it is active without any errors.
Now, let us connect to the Redis server using the Redis command-line interface (redis-cli).
Simply type the below command to connect to Redis Server:
We will get a prompt like this, with the Server address and Port (which can be found using
sudo systemctl status redis)
4.1) Send ping messages
Let us send a ping message to the Server. If it is active, we will get a response from the Server.
You should get a similar output on typing ping and ping Hello.
4.2) Verify key-value storage
Now, let us check that we can be able to set Keys.
Let us set a Key called test with a value called “Sample Key“
127.0.0.1:6379> set test "Sample Key"
Retrieve the value of the test using:
127.0.0.1:6379> get test
exit to go back to the Shell Prompt.
Now, we have successfully verified that our Redis Server is working properly, and can respond to our queries as expected!
In this tutorial, we learned how to install and configure Redis Server on Ubuntu 18.04, which is used for storing key-value pairs efficiently.
I hope this was useful to you for setting up your own Redis Server!