How to install Redis on Ubuntu and CentOS (Linux)

Redis is most popular open-source key-value data store in-memory database that can be used as a cache server, message broker, etc. In this guide, we will learn how to install Redis on Ubuntu and CentOS servers. This guide describes how to install Redis on Ubuntu and CentOS (Linux).

Redis also provides a number of features given below,

  • Replication
  • data persistence
  • LRU eviction
  • High availability using sentinel
  • Publish / Subscribe support for data
  • Keys with limited TTL
  • Automatic Failover
  • LUA scripting

Install Redis on Ubuntu

By default Redis packages is available in Ubuntu repositories, So just perform a repos update before that,

$ sudo apt update

Next install redis on ubuntu with the below command,

$ sudo apt install redis

Now start the redis service using below command.

$ sudo systemctl start redis

Install Redis on CentOS

Redis packages is available on EPEL repository, so you can install the EPEL repository on our CentOS/ RHEL machine. Install it using below command,

# yum install epel-release

Once the epel repository is installed in your system, you can install redis with the below command,

# yum install redis

Start service using the below command,

# systemctl start redis

Install Redis Using Source on CentOS

Using this method, you can install the latest version of redis. You will installing the latest version at this time, i.e. 6.0.9.. Download the redis package using below command,

# wget https://download.redis.io/releases/redis-6.0.9.tar.gz

Next extract the redis package with the following command,

# tar -xvf redis-6.0.9.tar.gz

Now go to the extracted folder,

# cd redis-6.0.9
# cd deps

next compile packages,

# make hiredis lua jemalloc linenoise
# make geohash-int

Next, move back to the main directory i.e. ‘redis-6.0.9’. execute below commands.

# cd ../
# make
# make installation

Once you will execute commands, next you will install the init scripts, init script will setup a redis service with port number, config file, log file & a data directory.

# cd utils\

& run the install_server.sh script,

# ./install_server.sh

Hence you will now be asked with some information regarding redis server, as shown below,

Modify settings as per your requirements & you can also install more than one redis instances by just changing the default redis port. Now start the redis service using below command which is different that conventional command,

# systemctl start redis_6379

Testing Redis installation

You can now check if the redis has been installed by running the following command,

$ redis-cli --version

You can also connect to the installed redis server with the following command,

$ redis-cli

Next check the response to ping command for redis,

redis > PING

redis installation on linux

In response, you should get PONG as output.

Allowing remote connections to Redis installation

By default, you can only connect to redis server from the local server. To allow connections to redis installation from remote machines, you need to make changes to redis configuration file,

$ sudo vi /etc/redis/redis.conf

Then search for section that says ‘bind 127.0.0.1’ & change it

bind 0.0.0.0

Connections can be allowed from all remote servers or you can also mention single or multiple IP addresses to allow connections from those servers only such as,

bind 10.10.10.10 192.168.1.10

Connections would be allowed from two machines with IP addresses 10.10.10.10 & from 192.168.1.10. Once the changes have been made, you need to restart the redis service to apply changes,

$ sudo systemctl restart redis

Conclusion

Hence, We have finished our practicals on how to install Redis on CentOS & RHEL. Please do send in any queries in below comment box.

Read Also : Top 20 Linux Find Command Practical Examples

Share on:

Ravindra Kumar

Hi, This is Ravindra. I am founder of TheCodeCloud. I am AWS Certified Solutions Architect Associate & Certified in Oracle Cloud as well. I am DevOps and Data Science Enthusiast.

Leave a Comment