How to Install Redis on Ubuntu 18.04 Server

In this tutorial we are going to learn how to install Redis on Ubuntu 18.04 Linux. For this tutorial I am going to use Ubuntu Server 18.04, but you can also use following guide to install Redis on Ubuntu 16.04 server as well.

How to Install Redis on Ubuntu 18.04 Server

To install Redis on Ubuntu 18.04 Server, First enable the universe apt repository, update the apt source list, then install the redis-server package.

add-apt-repository universe
apt-get update
apt-get install redis-server

Ubuntu redis-server package includes two main components, redis-server and redis-tools.

The redis-server is the Redis data store or the database. The redis-tools package provides the redis cli which is the command line tool that can use to perform redis commands.

To check the redis server version installed on your computer, run the following command:

redis-server --version
Check redis version on Ubuntu 18.04

View the status of the redis service with systemctl command:

systemctl status redis.service
View the status of the redis service with systemctl command

By default, Redis on Ubuntu runs on TCP port 6379. We can verify this by running the netstat command:

netstat -tulnp | grep redis
By default, Redis on Ubuntu runs on TCP port 6379.

Connect to the Redis Database Server

To connect to the redis server running on a local Ubuntu server, type:

redis-cli

If you want to access a redis server on a remote computer, you need to use the -h flag.

redis-cli -h 192.168.1.100

Starting and shutting down Redis on Ubuntu

Redis server will start automatically after the installation. We can manually start, restart and stop Redis using the systemctl command:

To start Redis on Ubuntu, run:

systemctl start redis.service

To stop Redis server, run:

systemctl restart redis.service

Allow Remote Access to the Database Server

By default Redis on Ubuntu run on the loopback interface which means server cannot be accessed from a remote computer. To allow remote access, do the following steps.

Open the main configuration file 'redis.conf':

vim /etc/redis/redis.conf

Find the line that reads 'bind 127.0.0.1 ::1' and Replace it with the following line:

bind 0.0.0.0 ::

Restart the redis service:

systemctl restart redis.service