Fixing "Bootstrap failed: 5: Input/output error" with Homebrew Services
When trying to start MongoDB or other services through Homebrew on macOS, you may encounter the frustrating "Bootstrap failed: 5: Input/output error" message. This comprehensive guide covers the most effective solutions to resolve this issue.
Problem Overview
The error typically appears when running brew services start [service-name]
and manifests as:
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/user/Library/LaunchAgents/homebrew.mxcl.service.plist` exited with 5.
This error can occur with various Homebrew services (MongoDB, PostgreSQL, MySQL, Redis, etc.) and often stems from permission issues, corrupted files, or configuration problems.
Primary Solutions
1. Basic Restart Sequence
Start with these simple steps that often resolve the issue:
brew services stop mongodb-community
brew services restart mongodb-community
If that doesn't work, try a system restart followed by starting the service:
brew services stop mongodb-community
# Restart your Mac
brew services start mongodb-community
TIP
Many users report that a simple system restart resolves the issue, especially after macOS updates.
2. Check Ownership and Permissions
Permission issues are a common cause of this error. Fix homebrew directory ownership:
sudo chown -R $(whoami) $(brew --prefix)/*
For MongoDB specifically, ensure proper permissions on data and log directories:
mkdir -p /opt/homebrew/var/mongodb
mkdir -p /opt/homebrew/var/log
sudo chown -R $(whoami) /opt/homebrew/var/mongodb /opt/homebrew/var/log
3. Manual Launch Agent Management
Sometimes the launch agent gets stuck and needs manual intervention:
# Unload the service
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
# Remove it completely
launchctl remove homebrew.mxcl.mongodb-community
# Reload it
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
4. Comprehensive Clean Reinstall
If the above steps fail, perform a complete cleanup and reinstall:
# Stop and unload the service
brew services stop mongodb-community
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
# Remove the plist file
rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
# Cleanup and reinstall
brew services cleanup
brew uninstall mongodb-community
brew install mongodb-community
# Start the service
brew services start mongodb-community
Diagnostic Approaches
Check Service Logs
Always examine the service logs for specific error messages:
# For MongoDB
tail -n 50 /opt/homebrew/var/log/mongodb/mongo.log
# For PostgreSQL
tail -n 100 /usr/local/var/log/postgresql@11.log
# For other services, check their respective log locations
Common issues revealed in logs include:
- Permission denied errors
- Port conflicts
- Database version incompatibilities
- Missing directories or files
Manual Service Testing
Test the service without Homebrew to identify the root cause:
# For MongoDB
mongod --dbpath /opt/homebrew/var/mongodb
# For PostgreSQL
postgres -D /usr/local/var/postgres
# For Redis
redis-server /usr/local/etc/redis.conf
This bypasses the launch agent system and often provides clearer error messages.
Check for Port Conflicts
Verify if another process is using the same port:
# Check for MongoDB default port (27017)
lsof -i :27017
# Check for PostgreSQL default port (5432)
lsof -i :5432
# Check for MySQL default port (3306)
lsof -i :3306
Advanced Scenarios
Database Version Incompatibility
When upgrading database versions (e.g., PostgreSQL 13 to 14), you might encounter:
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version X, which is not compatible with this version Y.
Solution: Use proper database upgrade procedures or maintain separate data directories for different versions.
Stuck PID Files
After abrupt system shutdowns, PID files might remain and prevent startup:
# For PostgreSQL
rm /usr/local/var/postgresql@11/postmaster.pid
# For other services, check their data directories for .pid files
macOS Permissions and Security
Recent macOS versions may require granting network access permissions:
- Attempt to start the service
- Check System Preferences → Security & Privacy → Privacy → Full Disk Access
- Grant permission if requested
Also ensure Xcode command line tools are installed:
xcode-select --install
Prevention and Best Practices
- Always stop services properly before shutting down your system
- Keep Homebrew and services updated regularly
- Backup important data before major upgrades
- Check compatibility when upgrading macOS or service versions
- Monitor logs regularly for early detection of issues
When to Seek Further Help
If none of these solutions work, consider:
- Checking the GitHub issues for your specific service formula
- Searching for macOS-specific troubleshooting guides
- Consulting the official documentation for your database/service
WARNING
Be cautious when using sudo
with Homebrew services as it can create permission conflicts between user and root-owned processes.
By methodically working through these solutions, most "Bootstrap failed: 5: Input/output error" issues can be resolved, restoring normal service operation.