Most backend developers on a Mac need the same handful of background services: a database, a cache, maybe a message broker or a search engine. Docker covers some of that, but plenty of teams still run Postgres and Redis natively because it is faster on a laptop, starts at login and does not eat a fixed slice of RAM. On macOS that usually means Homebrew or MacPorts.
We have used both across a team of about twenty engineers. This guide compares them on the part that actually causes support tickets: how services are installed, started, upgraded and removed, where files land, and what goes wrong when both tools end up on the same machine.
Where each tool puts things
The install prefix decides which binaries win on your PATH, which libraries a compiler finds and where data directories live.
Item | Homebrew | MacPorts |
|---|---|---|
Prefix on Apple Silicon |
|
|
Prefix on Intel Macs |
|
|
Data for services |
|
|
Config files |
|
|
Needs root for installs | No (prefix owned by your user) | Yes ( |
Binary packages | Bottles for most formulae | Prebuilt archives for many ports, falls back to building |
Installer | Shell script from brew.sh | Package per macOS release from macports.org |
Two consequences matter day to day. Homebrew assumes a single admin user owns the prefix, which is convenient on a personal laptop and awkward on a shared build Mac. MacPorts runs installs as root and keeps everything under /opt/local, which never collides with anything Apple ships and is easy to wipe completely.
Run this once on any machine you inherit to see what is going on:
type -a psql redis-server python3
brew --prefix 2>/dev/null
port version 2>/dev/null
echo "$PATH" | tr ':' '\n'
If both /opt/homebrew/bin and /opt/local/bin show up, read the section on mixing before you do anything else.
Starting services with Homebrew
Homebrew formulae that ship a daemon declare a service block. brew services turns that into a launchd property list and loads it.
brew install postgresql@17 redis
brew services start postgresql@17
brew services start redis
brew services list
brew services list prints the service name, status (started, stopped, error, none), the user it runs as and the plist path. Without sudo, the plist goes to ~/Library/LaunchAgents/homebrew.mxcl.<formula>.plist and the service starts when you log in. With sudo brew services start, it goes to /Library/LaunchDaemons and starts at boot as root, which is rarely what you want for a dev database and leaves root-owned files in your data directory.
Other subcommands worth knowing:
brew services run redis # start now, do not register for login
brew services restart postgresql@17
brew services stop postgresql@17
brew services info postgresql@17
brew services cleanup # remove plists for formulae that are gone
run is handy on a laptop where you only want Postgres while working on one project. cleanup matters after uninstalling, because a leftover plist will keep trying to start a binary that no longer exists and fill the unified log with spawn failures.
Logs usually land under $(brew --prefix)/var/log/, but the plist is the source of truth. brew services info prints its path, and plutil -p <path> shows StandardOutPath and StandardErrorPath.
Starting services with MacPorts
MacPorts calls the launchd wrapper a startupitem. Ports that include one install a plist under /opt/local/etc/LaunchDaemons/ and symlink it into /Library/LaunchDaemons/ when you load it.
sudo port install postgresql17-server redis
sudo port load redis
sudo port unload redis
For Postgres the port prints post-install notes telling you to create the data directory and run initdb as the postgres user it creates. Follow those notes literally; MacPorts does not initialise the cluster for you.
sudo mkdir -p /opt/local/var/db/postgresql17/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql17/defaultdb
sudo -u postgres /opt/local/lib/postgresql17/bin/initdb -D /opt/local/var/db/postgresql17/defaultdb
sudo port load postgresql17-server
Because these are LaunchDaemons, they start at boot and run as a dedicated system user. That is closer to how the service runs on a Linux server, at the cost of needing sudo for every start and stop.
MacPorts also has port select, which picks the default among several installed versions of the same tool:
port select --list postgresql
sudo port select --set postgresql postgresql17
Homebrew has no direct equivalent; it uses keg-only versioned formulae and you add the one you want to PATH yourself.
Upgrades: the part that breaks things
Upgrades are where the two tools differ most in practice.
Homebrew updates its formula index automatically before many commands and brew upgrade upgrades everything outdated unless you pin it. For services with on-disk formats, use the versioned formula (postgresql@17, mysql@8.4) so a routine upgrade only moves you within a major line. brew pin <formula> freezes a formula completely, including patch releases, so use it sparingly and write down why.
MacPorts upgrades only when you run it:
sudo port selfupdate
port outdated
sudo port upgrade outdated
Its database ports are already split per major version (postgresql16-server, postgresql17-server), so a major jump is always a deliberate install. The bigger MacPorts event is a macOS major upgrade: the project's migration guide tells you to install the MacPorts release for the new macOS version, then reinstall all ports. Ports built against the old SDK can fail in odd ways if you skip it. Budget an hour for that after every macOS major upgrade.
Homebrew handles a macOS upgrade more quietly, but after one we routinely run brew doctor and reinstall the Xcode Command Line Tools if brew complains about them.
Mixing both: why it hurts
Having both installed is not forbidden, but it creates three classes of problems we have hit repeatedly:
Wrong binary on
PATH.psqlfrom one prefix talks to a server from the other with a different socket directory, so you get "connection refused" while the server is clearly running.Build contamination. A
./configurescript or a Ruby/Python native extension finds headers in/opt/local/includeand libraries in/opt/homebrew/lib, then fails at link or run time with symbol errors.Port collisions. Two Redis daemons both want 6379. Whichever loaded first wins; the other logs a bind error forever.
If someone genuinely needs both, keep one prefix out of the default PATH and add it only inside a project shell. Never point a compiler at both prefixes at once.
Keeping setups reproducible
Homebrew has brew bundle. A Brewfile in the repo lists formulae and can manage services:
brew "postgresql@17", restart_service: :changed
brew "redis", restart_service: :changed
brew "jq"
Then brew bundle install sets up a new laptop and brew bundle check tells you if anything is missing. brew bundle dump writes the current state, which is a useful starting point but always includes personal tools, so edit it before committing.
MacPorts has no manifest file, but the migration guide shows how to capture what you requested:
port -qv installed > myports.txt
port echo requested | cut -d ' ' -f 1 | uniq > requested.txt
Keep requested.txt in a dotfiles repo and reinstall with a small loop.
Which one to choose
Situation | Better fit | Why |
|---|---|---|
Personal laptop, mainstream stack | Homebrew | Bottles install fast, huge formula catalogue, |
Team onboarding script | Homebrew |
|
Shared or locked-down Mac | MacPorts | Root-owned prefix, services as dedicated users |
Need older or unusual library variants | MacPorts | Variants such as |
Want services to resemble a Linux server | MacPorts | LaunchDaemons, per-service system users |
Already mixed and confused | Pick one, uninstall the other | Both uninstall guides are short and complete |
Whichever you choose, the rules that keep a team sane are the same: one package manager per machine, versioned formulae or ports for anything with a data directory, a committed manifest, and services started per user unless there is a reason to run them at boot.
Common mistakes
Mistake | Why it hurts | Do this instead |
|---|---|---|
| Root-owned data files, starts at boot | Plain |
Unversioned database formula | Major upgrade lands during a routine |
|
Skipping MacPorts migration after macOS upgrade | Ports linked against old SDK misbehave | Reinstall MacPorts for the new OS, reinstall ports |
Uninstalling without | Stale plist keeps respawning | Run |
Both prefixes on | Mismatched client/server, broken builds | One prefix, or isolate the second per shell |
Key takeaways
Homebrew lives in
/opt/homebrewon Apple Silicon, MacPorts in/opt/local; checktype -abefore debugging anything else.brew serviceswrites per-user LaunchAgents by default;port loadinstalls LaunchDaemons that start at boot.Use versioned packages for any service that stores data, and pin only with a written reason.
MacPorts needs a reinstall after macOS major upgrades; plan for it.
Commit a
Brewfileor a requested-ports list so a new laptop is one command away.
References
Homebrew documentation: https://docs.brew.sh/
Homebrew
brew servicesandbrew bundlemanual: https://docs.brew.sh/ManpageHomebrew installation and default prefixes: https://docs.brew.sh/Installation
MacPorts Guide: https://guide.macports.org/
MacPorts migration after a macOS upgrade: https://trac.macports.org/wiki/Migration
Apple launchd overview: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.