brew-services
Manage Homebrew-installed services
TLDR
List all managed services for the current user
List more information about all managed services
Start a service immediately and register it to launch at login (or boot)
Stop the service immediately and unregister it from launching at login (or boot)
Stop (if necessary) and start the service immediately and register it to launch at login (or boot)
Remove all unused services
SYNOPSIS
brew services subcommand [options] [service ...]
Common subcommands:
list
start service [...][options]
stop service [...][options]
restart service [...][options]
run service [options]
cleanup
info service
PARAMETERS
list
Lists all services managed by Homebrew, showing their status (started, stopped), user, and plist file path.
start service [...]
Starts the specified Homebrew service(s). This will generate and load a launchd .plist file, ensuring the service runs in the background and often restarts automatically.
stop service [...]
Stops the specified Homebrew service(s). This unloads the launchd .plist file and terminates the running process.
restart service [...]
Restarts the specified Homebrew service(s). This is equivalent to running stop followed by start.
run service
Runs the specified Homebrew service in the foreground, typically for debugging purposes. It does not register the service with launchd.
cleanup
Removes old or orphaned service .plist files that are no longer associated with installed formulae.
info service
Displays detailed information about a specific Homebrew service, including its status, process ID, and the location of its .plist file.
--all
Used with start, stop, or restart to apply the command to all currently managed Homebrew services.
--user
(Default) Manages services as user agents, typically running in ~/Library/LaunchAgents/. These services start when the user logs in.
--system
Manages services as system daemons, typically running in /Library/LaunchDaemons/. These services start at boot and run as the root user. Requires sudo.
--force
Forces the operation, for example, to force start a service even if it appears to be already running or has issues.
--file=
Specifies an alternative .plist file to use for the service, overriding the default generated one.
--debug
Show debug output for troubleshooting.
--verbose
Show verbose output.
DESCRIPTION
brew services is a crucial subcommand within the Homebrew package manager, designed to streamline the management of background processes, also known as services, installed through Homebrew formulae. It primarily leverages macOS's built-in launchd framework to ensure services start automatically at login or system boot, restart reliably upon crashes, and manage dependencies effectively.
This command abstracts away the complexities of dealing directly with launchd .plist files and launchctl commands, providing a user-friendly interface for common service operations. Developers and users frequently rely on brew services to effortlessly start, stop, restart, list, and link/unlink applications such as databases (e.g., PostgreSQL, Redis), web servers (e.g., Nginx, Apache), and other long-running daemons or agents necessary for their development or production environments.
CAVEATS
- Platform Dependency: brew services is primarily designed for macOS and relies heavily on the launchd service management framework. While Homebrew can be installed on Linux (Linuxbrew), the brew services functionality might be less robust or require additional system-specific configurations (e.g., with systemd) for full service management.
- Root Privileges: Managing system-level services with the --system flag requires sudo privileges, as these services typically run as the root user and start at system boot.
- Homebrew-Installed Services Only: brew services can only manage services that were installed via Homebrew formulae and are configured to be managed by it. It cannot manage arbitrary system services or applications installed outside of Homebrew.
- Configuration Overrides: While brew services simplifies management, some services may require specific configuration adjustments that go beyond its scope, often involving editing the service's configuration files directly.
SERVICE CONFIGURATION FILES (<I>.PLIST</I>)
At its core, brew services interacts with launchd by creating and managing XML-based configuration files known as Property List (.plist) files. These files contain instructions for launchd on how to run a service, including its executable path, arguments, environment variables, and restart behavior. brew services typically places user-specific agents in ~/Library/LaunchAgents/ and system-wide daemons in /Library/LaunchDaemons/.
INTEGRATION WITH <I>LAUNCHCTL</I>
brew services acts as a high-level wrapper around the lower-level launchctl command, which is the primary command-line interface for interacting with the launchd daemon on macOS. When you use brew services, it automatically generates and loads/unloads the necessary .plist files via launchctl load and launchctl unload commands, abstracting these details from the user.
HISTORY
brew services has been an integral part of the Homebrew ecosystem for many years, significantly enhancing its utility for macOS users. It was introduced to provide a more intuitive and automated approach to managing background processes compared to manually interacting with launchd and its complex .plist files. Its development has focused on robust error handling, seamless integration with launchd's capabilities, and simplifying common service management tasks, making it an indispensable tool for developers setting up local development environments with Homebrew-installed dependencies like databases, message queues, and web servers.