Install Redis with auto restart on CentOS 6, 7

Category : Redis

Today we will share a guide to install Redis on CentOS Machine (incl. cPanel based server) . This guide is compatible with both CentOS 6 and 7 and provides solution of automatic start of redis service on server reboot/start.

We will install it for the user only not for root but we have covered for users who want it as root and want all users to use the Redis

We will Here we start:-


  • Linux Machine with CentOS 6/7 with Root Permissions
  • Internet Connection


Compile Redis from Source

  1. Install some required packages (needs root permissions)

    sudo yum install wget make gcc tcl -y

  2. Download latest stable source for Redis from official release directory.


  3. Extract tar ball

    tar -xvf redis-stable.tar.gz

  4. Run the following commands one by one to compile Redis from source
    Please note that make commands below will take some time to complete, so keep patience

    cd redis-stable
    cd deps
    make hiredis lua jemalloc linenoise
    cd ..
    make test

  5. If make test commands show output as below then you have successfully compiled Redis.
  6. If you want to install for all users on your machine run the following command or else skip it (root permissions required)

    sudo make install

Install init Script

We need init configuration so that redis-server should start itself on boot and no manual commands are needed by the user.
Note – We need root to create init Script

  1. Goto your redis-stable directory where you have compiled Redis from source using above steps

    cd /full/path/redis-stable
    cd src

  2. Run the following command to get full path of your Redis dir, which I needed when creating init Script


    As is above photo for me full path is /home/deepak/redis-stable

  3. Goto utils directory in redis-stable

    cd utils

  4. Run script as root

    sudo ./

    It will ask you some details while creating init script. To keep default just press ENTER Please select the redis port for this instance: [6379]
    Selecting default: 6379
    Please select the redis config file name [/etc/redis/6379.conf]
    Selected default – /etc/redis/6379.conf
    Please select the redis log file name [/var/log/redis_6379.log]
    Selected default – /var/log/redis_6379.log
    Please select the data directory for this instance [/var/lib/redis/6379]
    Selected default – /var/lib/redis/6379
    Please select the redis executable path [] /home/deepak/redis-stable/src/redis-serverIn my config, I have used everything default and have customized only the ‘redis executable path’, which means that we have to define the path where we have compiled the Redis ourselves.
    So, now we will use the full path of redis-stable dir generated in Step #2 above and for me redis is compiled inside ‘src’ dir so for me redis executable path is /home/deepak/redis-stable/src/redis-server
    Press enter after entering correct path and it will show you the selected configuration, just cross check and press ENTER to confirm.
    Note- Users who have installed it as root don’t need to change the ‘redis executable path’

  5. If everything goes correct then install_server script will show success message on your terminal window.
  6. Now we have to start the service created by init script which needs root permissions
    For CentOS 6 run

    service redis_6379 start

    For CentOS 7 run

    systemctl start redis_6379

    Note –  If you have used custom port then your service name should be different.

Create alias for redis-cli
This is only needed if you have installed for specific user and not as root

  1. Edit .bashrc file for alias

    nano ~/.bashrc

  2. Paste the following lines at the end

    alias redis-cli=~/redis-stable/src/redis-cli
    alias redis-server=~/redis-stable/src/redis-server

    Note- Please adjust if your redis-stable dir in not in root of your user.

  3. Apply .bashrc changessource ~/.bashrc

Test redis

  1. Run redis-cli using following command and run proceeding commands to test redis.

    > set welcome “Hello from BaseZap”
    > get welcome

    The output should be “Hello from BaseZap”

    So, we have finished the Installation for Redis on CentOS Machine.