How to Install Redis on Ubuntu Using the APT Command
Redis is a popular, open-source, in-memory data structure store used as a database, cache, and message broker.
Installing Redis on Ubuntu is straightforward, thanks to the Advanced Package Tool (APT), which simplifies installing software on Debian-based Linux systems like Ubuntu. Here’s a step-by-step guide on how to install Redis using APT.
Step 1: Update Your System
Before installing any new software, it’s good practice to update your package lists to ensure you have the latest versions available. Open your terminal and type:
1 | sudo apt update |
This command refreshes the list of available packages, which helps avoid potential issues during the installation.
Step 2: Install Redis
Now, you can install Redis with the following command:
1 | sudo apt install redis-server -y |
The -y
flag automatically confirms the installation, so you won’t need to approve it manually. This command installs the Redis server and other dependencies.
Step 3: Verify the Installation
Once the installation is complete, you can verify it by checking the Redis version:
1 | redis-server --version |
This command should return the version number of Redis installed on your system, confirming that the installation was successful.
Step 4: Start and Enable the Redis Service
To ensure Redis starts automatically with your system, enable the Redis service:
1 | sudo systemctl enable redis-server |
Then, start the Redis service:
1 | sudo systemctl start redis-server |
You can check the status of the Redis service to confirm it’s running:
1 | sudo systemctl status redis-server |
If Redis is running, you’ll see an “active (running)” status.
1 | $ sudo systemctl status redis-server |
Step 5: Test the Redis Installation
To confirm that Redis is functioning as expected, you can use the redis-cli
(Redis Command Line Interface) to connect to the Redis server and run a simple command. Type:
1 | redis-cli ping |
If Redis is working correctly, you’ll see a response of PONG
, indicating a successful connection to the Redis server.
1 | $ redis-cli ping |
Optional: Configure Redis
For production environments, it’s essential to configure Redis securely. By default, Redis is configured to run in an open state, which is suitable for development but may require additional configuration for production. For example, you can modify the Redis configuration file located at /etc/redis/redis.conf
to set up a password, configure persistent storage, and more. After making any changes to this file, restart the Redis service:
1 | sudo systemctl restart redis-server |
Conclusion
With these steps, you’ve successfully installed Redis on your Ubuntu system using the APT package manager. Redis is now ready for use as an in-memory cache, database, or message broker on your server. For additional security and performance tuning, consider exploring the Redis configuration file and adjusting settings based on your specific needs.