Redis is an in-memory key-value data structure store. It’s become the go-to solution for organizations and developers because of efficient performance and flexibility. Redis is typically utilized in real-time scenarios, for instance, background jobs, messaging, caching, and analytics. Moreover, it is written in C language and supports a wide range of data types, such as strings, lists, hashes, and others.
This blog will teach you how to install Redis on Ubuntu 22.04. There are three methods for installing Redis. Let’s demonstrate them one by one!
Method 1: How to Install Redis from APT Repository on Ubuntu 22.04?
To install the Redis from the Ubuntu official repository, first update and upgrade the local apt package list by executing the following command:
sudo apt update && sudo apt upgrade |
---|
To install the Redis, run the following command:
sudo apt install redis |
---|
Here, we installed the “redis” package which includes all the essentials:
Now, check the version of Redis to ensure its installation through the provided command:
redis-server --version |
---|
According to the given output, the latest version “6.0.16” of Redis has been installed successfully on Ubuntu 22.04:
After the installation, let’s run the given command to check the current status of the Redis service:
sudo systemctl status redis |
---|
Note: according to the above-given output, our Redis server is active. In case, if it is not, then you can start it by executing the following command:
sudo systemctl start redis |
---|
Method 2: How to Install Redis via Redis Repository on Ubuntu 22.04?
Here is another method for installing the Redis via its repository on Ubuntu 22.04. For that particular purpose, first, install the “Isb_release” tool that is necessary to get the Ubuntu version including the “curl” and “gpg” utilities that help in downloading the GPG key:
sudo apt install lsb-release curl gpg |
---|
Next, authenticate the Redis repository by adding the GPG key through the following command:
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg |
---|
Now, trace your Ubuntu version and add the Redis repository by running the below-stated command to your sources list:
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list |
---|
After doing so, run the “apt update” command to update the package list:
sudo apt update |
---|
Finally, to install the Redis service, use the provided command:
sudo apt install redis |
---|
To verify the successful installation of Redis on Ubuntu 22.04, use the given command to check the version:
redis-server --version |
---|
Method 3: How to Install Redis from Snap on Ubuntu 22.04?
You can install Redis from the Snap Store but maintain it differently than the Ubuntu official repositories method. To do so, execute the “snap install redis” command to install the Redis:
sudo snap install redis |
---|
As we described earlier, Snap manages Redis on its own. For that purpose, the below given “snap start redis” command to start the Redis, “snap enable redis” command to enable Redis, and “snap enable redis” command to restart the Redis are used:
sudo snap start redis sudo snap enable redis sudo snap restart redis |
---|
Now, use the given command to check if the Redis service is working or not:
sudo systemctl status redis |
---|
Then, execute the “redis-cli” command to access the Redis server and the “ping” command to test the Redis connectivity:
redis-cli ping |
---|
The “PONG” output confirms that the server connection is working correctly:
After doing so, set the key-value pair by running the “set” command:
Redis-cli set test "Redis is working on Ubuntu22.04" |
---|
Here, “test” is the Key, and the “Redis is working on Ubuntu22.04” is the key value:
Now to check the key value, execute the “get” command:
get test |
---|
Lastly, execute the “exit” command to close the Redis prompt for getting back to the shell:
exit |
---|
If you want to delete the key-value pair, run the “del” command along with the particular key name. For instance, here “test” is our key:
del test |
---|
How to Remove apt-based Redis from Ubuntu 22.04?
Users often encounter multiple situations (such as Redis crashing) where they want to uninstall/remove Redis from their Ubuntu 22.04 system. To do so, multiple methods are available that depend on their installation method.
Here, if you have installed Redis using the Ubuntu official repository or via the Redis repository, execute the below command to permanently uninstall Redis from the system:
sudo apt autoremove redis --purge |
---|
How to Remove Snap-based Redis from Ubuntu 22.04?
Use the provided command if you have installed the Redis server from the Snap store:
sudo snap remove redis --purge |
---|
That was all about the installation of the Redis on Ubuntu 22.04.
Conclusion
Redis is an open-source key-value data store that offers more caching speed for read/write operations. It can be installed on Ubuntu from its official repository, the Redis repository, and the Snap store. Furthermore, the Redis repository and Snap store offer the most latest version however, Snap provides minimal control over the Redis due to its self-management nature. We have described the different ways of installing Redis on Ubuntu 22.04.
Leave feedback about this