Homebrew¶
Homebrew is a package manager for macOS (and Linux). It installs system-level software, including Python itself.
What is Homebrew?¶
Homebrew installs system packages that aren't managed by pip or conda: - Python interpreter - Git, curl, wget - Databases (PostgreSQL, Redis) - Command-line tools - Libraries (OpenSSL, libffi)
Website: https://brew.sh
Installation¶
macOS¶
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Linux¶
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Verify¶
brew --version
Basic Commands¶
Install Package¶
brew install python
brew install git
brew install postgresql
Upgrade Package¶
brew upgrade python
brew upgrade # Upgrade all
Uninstall Package¶
brew uninstall python
Search Packages¶
brew search python
List Installed¶
brew list
brew list --versions
Package Info¶
brew info python
Installing Python with Homebrew¶
Install Latest Python¶
brew install python
This installs:
- python3 command
- pip3 command
- Latest stable Python version
Check Installation¶
which python3
# /opt/homebrew/bin/python3 (Apple Silicon)
# /usr/local/bin/python3 (Intel Mac)
python3 --version
pip3 --version
Multiple Python Versions¶
brew install python@3.10
brew install python@3.11
brew install python@3.12
# Use specific version
python3.10 --version
python3.11 --version
Homebrew vs pip vs conda¶
| Tool | Installs | Use For |
|---|---|---|
| Homebrew | System packages | Python interpreter, git, databases |
| pip | Python packages | numpy, pandas, requests |
| conda | Python + system packages | Data science environments |
Typical Workflow¶
# 1. Install Python with Homebrew
brew install python
# 2. Create virtual environment
python3 -m venv myenv
source myenv/bin/activate
# 3. Install Python packages with pip
pip install numpy pandas
Useful Packages for Python Development¶
# Python interpreters
brew install python
brew install python@3.10
brew install pypy3
# Development tools
brew install git
brew install gh # GitHub CLI
brew install pre-commit
# Databases
brew install postgresql
brew install mysql
brew install redis
brew install sqlite
# Data tools
brew install jq # JSON processor
brew install csvkit # CSV tools
# System libraries (sometimes needed by pip)
brew install openssl
brew install libffi
brew install zlib
Casks: GUI Applications¶
Homebrew Cask installs GUI applications:
# IDEs and editors
brew install --cask visual-studio-code
brew install --cask pycharm-ce
# Terminals
brew install --cask iterm2
# Database tools
brew install --cask dbeaver-community
brew install --cask tableplus
# General
brew install --cask docker
brew install --cask slack
Services¶
Homebrew can manage background services:
# Start PostgreSQL
brew services start postgresql
# Stop PostgreSQL
brew services stop postgresql
# Restart
brew services restart postgresql
# List running services
brew services list
Maintenance¶
Update Homebrew¶
brew update # Update formula definitions
Upgrade All Packages¶
brew upgrade
Clean Up¶
brew cleanup # Remove old versions
brew autoremove # Remove unused dependencies
Doctor (Troubleshooting)¶
brew doctor # Check for issues
Common Issues¶
Permission Errors¶
# Fix permissions
sudo chown -R $(whoami) /opt/homebrew # Apple Silicon
sudo chown -R $(whoami) /usr/local # Intel Mac
Conflicting Python Versions¶
# See which Python is being used
which python3
python3 --version
# Link specific version
brew link python@3.11
PATH Issues¶
Add to ~/.zshrc or ~/.bashrc:
# Apple Silicon Mac
eval "$(/opt/homebrew/bin/brew shellenv)"
# Intel Mac
eval "$(/usr/local/bin/brew shellenv)"
Homebrew on Linux (Linuxbrew)¶
Homebrew also works on Linux:
# Install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add to PATH
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
source ~/.bashrc
Useful for:
- Installing newer software than system packages
- Consistent tooling across macOS and Linux
- Avoiding sudo apt install permission issues
Summary¶
| Command | Description |
|---|---|
brew install pkg |
Install package |
brew upgrade pkg |
Upgrade package |
brew uninstall pkg |
Remove package |
brew search name |
Search packages |
brew list |
List installed |
brew info pkg |
Package details |
brew update |
Update Homebrew |
brew upgrade |
Upgrade all packages |
brew cleanup |
Remove old versions |
brew services start pkg |
Start service |
brew install --cask app |
Install GUI app |
Key Takeaways¶
- Homebrew installs system packages (Python, Git, databases)
- Use Homebrew for Python interpreter, pip/conda for Python packages
brew install --caskfor GUI applicationsbrew servicesmanages background services- Works on both macOS and Linux
- Run
brew doctorto troubleshoot issues