Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes

Install Redis on macOS

Step-by-step guide to installing Redis on macOS for local development. Covers Homebrew, configuration, starting the server, and verification.

Focus: install redis on macos

Sponsored

Nothing kills developer momentum like wrestling with a database install — permission errors, missing dependencies, or a cryptic command not found after what you thought was a successful setup. Redis, the lightning-fast in-memory data store, is a staple for caching, session management, and real-time features, but getting it running on macOS should be a 60-second task, not a detour. This lesson hands you the exact steps to install Redis on macOS, verify it works, and have it ready for your projects — no config wizardry required.

The problem this lesson solves

You need Redis running locally — to test a caching layer, prototype a real-time app, or follow along with a tutorial. The frustration: Homebrew says Redis is installed, but redis-server complains about permissions, or redis-cli returns Connection refused. Without a clean install, you waste time debugging instead of coding. This lesson eliminates those dead ends by showing you the canonical method, plus how to handle the most common gotchas on macOS.

Core concept / mental model

Think of Redis as a super-fast dictionary in the cloud — except it lives on your own machine. Installing Redis means setting up two things:

  • The server (redis-server): a background process that listens for commands and stores data in memory.
  • The CLI (redis-cli): a command-line tool to talk to the server — send commands like SET name "Alice" and get OK back.

On macOS, the most reliable way is Homebrew, the package manager that handles dependencies and paths for you. You don't compile from source or need a VM. One formula (redis) gives you both server and CLI, plus a launchd plist to run Redis as a macOS service.

How it works step by step

  1. Install Homebrew if you don't have it. One command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Redis with brew install redis — this downloads the binary and config.
  3. Start the server — either foreground (redis-server) or background via Homebrew services (brew services start redis).
  4. Verify with redis-cli ping. If it returns PONG, you're live.
  5. Optional configuration — edit /usr/local/etc/redis.conf (or /opt/homebrew/etc/redis.conf on Apple Silicon) to set password, port, or persistence.

The key insight: Homebrew handles the PATH and dependencies. You don't need to set environment variables or install Python bindings first.

Hands-on walkthrough

Step 1: Check Homebrew

Open Terminal and run:

brew --version

Expected output (version may differ):

Homebrew 4.2.10
Homebrew/homebrew-core (git revision ...)

If brew is not found, install it from brew.sh.

Step 2: Install Redis

brew install redis

You'll see Homebrew download and compile. When complete:

...
To start Redis now and restart at login:
  brew services start redis
Or, if you don't want/need a background service you can just run:
  # Start Redis in the foreground
  redis-server /usr/local/etc/redis.conf

Step 3: Start Redis as a service (recommended)

brew services start redis

Output:

==> Successfully started `redis` (label: homebrew.mxcl.redis)

This keeps Redis running in the background, even after you close Terminal.

Step 4: Verify the server

redis-cli ping

Output:

PONG

You can also test a simple key-value pair:

# test_redis.py
import redis

r = redis.Redis()
r.set('hello', 'world')
print(r.get('hello').decode()) # Output: world

Pro tip: If the Python example fails with ModuleNotFoundError: No module named 'redis', install the client library: pip install redis.

Step 5: Stop Redis (when done)

brew services stop redis

Or run it once in the foreground with:

redis-server

Then press Ctrl+C to stop.

Compare options / when to choose what

Method Ease Persistence Background Best for
Homebrew (brew install) ⭐⭐⭐ 🔁 Launches at login via launchd ✅ Background service General development — always on, no manual start
Docker (docker run redis) ⭐⭐ ❌ Lost when container stops (unless volume) ✅ Background container Isolated environments — different versions, clean state per run
Manual build from source 🔁 Up to you Manual config Custom builds — patching, unusual platforms

When to choose Homebrew: You want zero friction, Redis starts automatically, and you don't need a separate config per project.

When to choose Docker: You need specific Redis versions side by side, or you want to reset data easily by recreating the container.

Troubleshooting & edge cases

redis-cli gives Connection refused (61)

The server isn't running or is not accepting connections.

  • Check if Redis is running: brew services list | grep redis
  • Start it: brew services start redis
  • If still failing, run redis-server in foreground and watch for error messages in the logs.

redis-server crashes on startup with Can't open the log file: Permission denied

Default log location may need privileges. Fix by editing /usr/local/etc/redis.conf:

# Change this:
logfile /var/log/redis/redis.log
# To:
logfile /usr/local/var/log/redis.log

Create the directory if needed: mkdir -p /usr/local/var/log.

brew install fails with No available formula

Homebrew's core repository may be outdated. Update:

brew update
brew tap homebrew/core
brew install redis

Apple Silicon (M1/M2) — paths differ

On Apple Silicon Macs, Homebrew installs to /opt/homebrew instead of /usr/local. The config file is at /opt/homebrew/etc/redis.conf. Commands like brew and redis-cli should be on your PATH automatically if you installed Homebrew correctly.

Pro tip: If brew services doesn't work, you might need to grant Homebrew Full Disk Access in System Settings → Privacy & Security.

What you learned & what's next

You now have Redis installed on macOS — running as a background service, with the CLI ready for action. You can:

  • Start and stop Redis using brew services
  • Connect via redis-cli or from Python using redis.Redis()
  • Troubleshoot the three most common issues: port conflicts, permission errors, and outdated Homebrew

Next lesson: Now that Redis is installed, learn how to store and retrieve data with basic commands — SET, GET, EXPIRE, and working with TTL (time-to-live). This is the foundation for caching and session stores.

Practice recap

Mini exercise: After installing, start Redis, use redis-cli to set a key (e.g., SET myname "YourName") and get it back. Then write a Python script that reads the same key and prints it. This verifies both server and client work end-to-end.

Common mistakes

  • Running redis-server directly without brew services start — closes when Terminal exits and won't restart on login.
  • Forgetting to install the redis Python client — import redis fails even though the server is running. Run pip install redis.
  • Editing /usr/local/etc/redis.conf but not restarting the service — changes take effect only after brew services restart redis.
  • On Apple Silicon, searching for config at /usr/local/etc instead of /opt/homebrew/etc — leads to 'file not found' errors.

Variations

  1. Instead of Homebrew, use Docker: docker run -d -p 6379:6379 redis:7-alpine for an isolated, ephemeral instance.
  2. Install via MacPorts: sudo port install redis — same concept but different package manager.
  3. Compile from source for custom patches: git clone https://github.com/redis/redis.git && cd redis && make && make install.

Real-world use cases

  • Cache database query results in a Django app — install Redis locally to test caching logic before deploying.
  • Run a real-time leaderboard for a game using Redis sorted sets — local install is needed for development.
  • Set up a simple message queue with Redis pub/sub for microservice communication during local development.

Key takeaways

  • Homebrew's brew install redis is the fastest, most maintainable method for macOS.
  • Use brew services start redis to keep Redis running in the background automatically.
  • Verify installation with redis-cli ping — a PONG reply confirms the server is ready.
  • Edit /usr/local/etc/redis.conf (Intel) or /opt/homebrew/etc/redis.conf (Apple Silicon) to customize port, password, or persistence.
  • Stop Redis with brew services stop redis — essential for clean shutdown before reboots.
  • Don't skip the Python client pip install redis — your app code needs it to connect.

Sponsored

Sponsored

Discussion

Questions, corrections, and tips help everyone reading this page.

0 comments

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters

No comments yet — start the thread.

Related tutorials, quizzes, and articles for this topic.