How to Install Redis on Ubuntu with Snap
Redis is a powerful, in-memory data structure store used as a database, cache, and message broker. It’s often used in web applications for high-performance caching and session management. Installing Redis on Ubuntu is easy and quick, especially using Snap, which simplifies installation and management. In this article, we’ll walk you through the steps to install Redis on Ubuntu using Snap.
What is Snap?
Snap is a package management system that allows you to install software packages (called “snaps”) in a secure and isolated environment. It ensures that you always have the latest version of the software, as snaps are automatically updated. Snap is supported on many Linux distributions, including Ubuntu.
Steps to Install Redis on Ubuntu with Snap
Update Your System
Before installing any software, it’s always a good idea to update your system’s package list to ensure you’re getting the latest available versions of packages. Open your terminal and run the following command:
1
sudo apt update
If there are any available updates for your system, you can install them with:
1
sudo apt upgrade
Install Snap (if not installed)
Most recent versions of Ubuntu come with Snap pre-installed. However, if for any reason Snap is not installed on your system, you can install it by running:
1
sudo apt install snapd
After installing Snap, you may need to log out and log back in, or restart your system, for the Snap commands to work properly.
Install Redis via Snap
With Snap installed, you can now install Redis. Snap makes this process incredibly simple. To install the official Redis snap package, run the following command:
1
sudo snap install redis
This command will automatically download and install the latest stable version of Redis. The snap package contains everything Redis needs to run, so you won’t need to worry about dependencies or configuration issues.
Check Redis Installation
Once the installation is complete, you can check if Redis is running by executing the following command:
1
snap info redis
This should return the version of Redis that was installed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34$ snap info redis
name: redis
summary: Redis is used as a database, cache and message broker.
publisher: Redis (redislabs)
store-url: https://snapcraft.io/redis
contact: redis@redis.io
license: unset
description: |
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache
and message broker. |
It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries,
bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. |
Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of
on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning
with Redis Cluster. |
|
Check out https://redis.io/ for more information.
commands:
- redis.benchmark
- redis.check-aof
- redis.check-rdb
- redis.cli
- redis.sentinel
services:
redis.server: simple, enabled, active
snap-id: hHi3Iys64CUmQLvb3OG1cOfj7fyffvwD
tracking: latest/stable
refresh-date: today at 17:04 CST
channels:
latest/stable: 7.4.1 2024-10-02 (1572) 10MB -
latest/candidate: ↑
latest/beta: ↑
latest/edge: 255.255.255 2024-03-10 (1566) 10MB -
**installed: 7.4.1 (1572) 10MB -**Start and Enable Redis
Redis installed via Snap should start automatically after installation. However, if it doesn’t, you can start it manually by running:
1
sudo snap start redis
To ensure Redis starts automatically on boot, run:
1
sudo snap enable redis
Access the Redis CLI
After starting Redis, you can access the Redis command-line interface (CLI) to interact with your Redis instance. Run the following command:
1
redis.cli
You should see the Redis prompt (
127.0.0.1:6379>
), where you can run Redis commands likePING
to test the connection:1
PING
Redis should respond with
PONG
.1
2
3
4$ redis.cli
127.0.0.1:6379> PING
PONG
127.0.0.1:6379>Configuring Redis (Optional)
Redis configuration files are typically located in
/var/snap/redis/current/redis.conf
when installed via Snap. You can modify these configuration files to suit your needs, such as changing the port or enabling authentication.To edit the configuration file, use a text editor like
nano
:1
sudo nano /var/snap/redis/current/redis.conf
After making changes, remember to restart Redis for the changes to take effect:
1
sudo snap restart redis
Uninstall Redis (if needed)
If you ever need to uninstall Redis, you can easily do so with Snap by running:
1
sudo snap remove redis
This will completely remove Redis from your system.
Conclusion
Installing Redis on Ubuntu using Snap is a fast, easy, and reliable method. With Snap, Redis is kept up to date automatically, and the installation process is streamlined, requiring minimal effort from the user. By following the steps above, you’ll have Redis up and running in no time, ready for use in your web applications or as a caching solution.