Install Redis on MacOS

To get Redis up and running on your Mac, you'll use a tool called Homebrew. It's like a handy app store for your command line, making software installation super easy. Let's walk through the steps to install and start Redis.
First off, you need to check if Homebrew is already on your Mac. Open your Terminal app – you can find it in Applications > Utilities > Terminal. Once it's open, type this command and hit Enter:
brew --version
If you see a version number, great! Homebrew is ready to go. If not, you'll need to install it by following the instructions on the Homebrew website.
With Homebrew in place, you're ready to install Redis. Back in the Terminal, type this command and press Enter:
brew install redis
This tells Homebrew to download and set up Redis on your Mac. It might take a minute, so just wait until it's done.
Now, let's start Redis and see if it works. You can run it in the foreground first, which means you'll see all the action happening right in your Terminal. Type this command:
redis-server
You should see a bunch of text scrolling by – that's Redis starting up. If you see something like "Ready to accept connections", Redis is up and running. To stop it, just press Ctrl-C
.
For a more practical setup, you can have Redis run in the background. This way, it starts automatically and keeps running even if you close your Terminal. To do this, type:
brew services start redis
This command uses a macOS feature called launchd
to manage Redis. To check if Redis is running in the background, use:
brew services info redis
You'll see whether Redis is running and other details about its status.
To stop Redis when it's running in the background, simply type:
brew services stop redis
Finally, let's make sure you can connect to Redis. Open a new Terminal window (or tab) and type:
redis-cli
This opens the Redis command line interface. To test the connection, type:
ping
If everything's working, you'll see PONG
in response.
And there you have it! You've installed Redis on your Mac using Homebrew, started it up, and even checked that it's working. Now you can explore more about Redis or start using it in your projects.