How To Install Redis Server In Ubuntu.
Introduction
Redis is an in-memory key-value store known for its flexibility, performance, and wide language support.
This tutorial is about how to install and configure Redis on Ubuntu Operating system.
Step 1: Installing and Configuring Redis
In order to get the latest version of Redis, we will use apt
to install it from the official Ubuntu repositories.
First, update your local apt
package cache if you haven’t done so recently:
Then, install Redis by typing:
This will download and install Redis and its dependencies. Following this, there is one important configuration change to make in the Redis configuration file, which was generated automatically during the installation.
Open this file with your preferred text editor:
Inside the file, find the supervised
directive. This directive allows you to declare an init system to
manage Redis as a service, providing you with more control over its
operation. The supervised
directive is set to no
by default. Since you are running Ubuntu, which uses the systemd init system, change this to systemd
:
That’s the only change you need to make to the Redis configuration file at this point, so save and close it when you are finished. Then, restart the Redis service to reflect the changes you made to the configuration file:
With that, you’ve installed and configured Redis and it’s running on your machine. Before you begin using it, though, it’s prudent to first check whether Redis is functioning correctly.
Step 2: Testing Redis
As with any newly-installed software, it’s a good idea to ensure that Redis is functioning as expected before making any further changes to its configuration. We will go over a handful of ways to check that Redis is working correctly in this step.
Start by checking that the Redis service is running:
If it is running without any errors, this command will produce output similar to the following:
Output● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2018-06-27 18:48:52 UTC; 12s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 2421 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 2424 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 2445 (redis-server)
Tasks: 4 (limit: 4704)
CGroup: /system.slice/redis-server.service
└─2445 /usr/bin/redis-server 127.0.0.1:6379
. . .
Here, you can see that Redis is running and is already enabled, meaning that it is set to start up every time the server boots.
To test that Redis is functioning correctly, connect to the server using the command-line client:
In the prompt that follows, test connectivity with the ping
command:
OutputPONG
This output confirms that the server connection is still alive. Next, check that you’re able to set keys by running:
OutputOK
Retrieve the value by typing:
Assuming everything is working, you will be able to retrieve the value you stored:
Output"It's working!"
After confirming that you can fetch the value, exit the Redis prompt to get back to the shell:
As a final test, we will check whether Redis is able to persist data even after it’s been stopped or restarted. To do this, first restart the Redis instance:
Then connect with the command-line client once again and confirm that your test value is still available:
The value of your key should still be accessible:
Output"It's working!"
Exit out into the shell again when you are finished:
With that, your Redis installation is fully operational and ready for you to use. That's it for the Tutorial Enjoy...!