How to install Redis
Redis is an open-source, in-memory data structure store that is frequently used to implement key-value databases, caches, and message brokers. According to the DB-Engines ranking, Redis is the eighth most popular database technology in the world, as well as the most popular key-value database. What's more, the 2019 Stack Overflow developer survey found that Redis was the "most loved" database, beating well-known competitors such as Microsoft SQL Server, MongoDB, Oracle, and MySQL.
That all sounds great - so how do you install Redis in the first place? In this article, we'll go over the steps to install Redis on Windows and Ubuntu Linux, so you'll be up and running in no time.
Installing Redis on Ubuntu
Installing Redis on Ubuntu is a snap - the Redis package is already included in the default Ubuntu repositories. Before getting started, be sure to update your apt package cache:
sudo apt update
The command to install Redis is as follows:
sudo apt install redis-server
Once the installation process is complete, there's one final step before you can start using Redis. Navigate to the Redis configuration file at "/etc/redis/redis.conf" and open it in your favorite text editor. For example:
sudo emacs -nw /etc/redis/redis.conf
The Redis configuration file is long and heavily annotated. Search for the following block of text near the beginning of the file:
# If you run Redis from upstart or systemd, Redis can interact with your # supervision tree. Options: # supervised no - no supervision interaction # supervised upstart - signal upstart by putting Redis into SIGSTOP mode # supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET # supervised auto - detect upstart or systemd method based on # UPSTART_JOB or NOTIFY_SOCKET environment variables # Note: these supervision methods only signal "process is ready." # They do not enable continuous liveness pings back to your supervisor. supervised no
Change the last line, "supervised no," to "supervised systemd." Save the file and exit. That's it - you're ready to get started.
You can also build Redis from source if you want more control over the installation process. To compile Redis from scratch, run the following sequence of commands:
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make
To test whether Redis has been built correctly, run the "make test" command. You can also install the Redis server and command-line interface with the "make install" command.
Your first step with Redis on Ubuntu should be a simple check of the Redis service. First, restart the Redis server to get it running:
sudo service redis-server restart
Second, start the Redis command-line interface:
From here, you can try a few simple commands, e.g.:
127.0.0.1:6379> set user:1 "Nikita" 127.0.0.1:6379> get user:1
If all goes well, you should see "Nikita" returned in the CLI window.
Finally, exit the Redis CLI with a Ctrl+C command, and shut down the Redis server:
sudo service redis-server stop
Installing Redis on Windows
Installing Redis on Windows isn't quite as easy as installing Redis on Ubuntu, but it's also not a complicated process. After years of not officially supporting Windows, Redis announced in 2018 that the project could run on Windows 10 using the Windows Subsystem for Linux (WSL), which allows Windows users to use native Linux command-line tools.
To install Redis on Windows, you'll first have to install WSL. Once that's complete, you'll have to choose a Linux distro to run on WSL: either Ubuntu 18.04, or Debian. We suggest using Ubuntu, in which case you can simply follow the instructions above to install Redis on Ubuntu.
Don't want to run Redis on WSL? You still have options to install Redis on Windows. GitHub user tporadowski has provided an unofficial Windows port of Redis. The GitHub repository contains forks for two different versions of Redis on Windows: a stable port of Redis 4.0.14 for Windows 64-bit, and a "fairly stable" port of Redis 5.0.9 for Windows 64-bit.
If you're running an older version of Windows, such as Windows 8.1, you can still install Redis on Windows. Redis provides instructions for installing Redis on Windows 8.1 in this blog post. Essentially, you'll need to download a Redis 3.2.1 port from MSOpenTech on GitHub. However, note that this version is no longer being actively maintained, nor is it officially approved by Microsoft. This port supports only Windows 64-bit, although the 32-bit version can be built from source.