← Back to Homebrew/brew

How to Deploy & Use Homebrew/brew

Homebrew Deployment and Usage Guide

Prerequisites

  • macOS (Intel or Apple Silicon) or Linux (x86_64, arm64, or armv7l)
  • Command Line Tools for Xcode (macOS only) - install with xcode-select --install
  • Git - for cloning the repository and managing taps
  • Ruby - Homebrew is written in Ruby and requires a compatible version

Installation

Installing Homebrew (Package Manager)

Homebrew is primarily distributed as a pre-built binary package. To install:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Building from Source

If you want to contribute to Homebrew or run from source:

  1. Clone the repository:
git clone https://github.com/Homebrew/brew.git
cd brew
  1. Install dependencies (Ruby gems):
gem install bundler
bundle install
  1. Add to your PATH (optional, for development):
export PATH="$(pwd)/Library/Homebrew/bin:$PATH"

Configuration

Environment Variables

Homebrew uses several environment variables for customization:

# Set custom Homebrew directory
export HOMEBREW_PREFIX="/opt/homebrew"

# Set Git editor for commit messages
export HOMEBREW_EDITOR="code --wait"

# Enable verbose output
export HOMEBREW_VERBOSE=1

Configuration Files

  • ~/.brewconfig - User-specific configuration
  • /usr/local/etc/brewconfig - System-wide configuration (macOS)
  • ~/.config/homebrew/config - User configuration (Linux)

Taps (Repositories)

Homebrew uses "taps" to extend available packages:

# Add a tap
brew tap homebrew/cask

# Add a custom tap
brew tap user/repo

# List all taps
brew tap

Build & Run

Development Environment

  1. Run tests:
bundle exec rake test
  1. Run specific tests:
bundle exec rake test TEST=test/unit/formula_test.rb
  1. Run RuboCop for code style:
bundle exec rubocop
  1. Run audit checks:
bundle exec brew audit --strict

Production Usage

Once installed, Homebrew commands work as documented:

# Update package list
brew update

# Install a package
brew install wget

# Upgrade all packages
brew upgrade

# Check system for potential issues
brew doctor

Deployment

Platform Recommendations

For Development/Contribution:

  • GitHub Actions - For CI/CD and automated testing
  • Docker - For isolated development environments

For Production Usage:

  • macOS - Native installation via the official installer
  • Linux - Native installation via the official installer

Deployment Steps

  1. Fork the repository on GitHub
  2. Clone your fork:
git clone https://github.com/your-username/brew.git
  1. Set up remote upstream:
git remote add upstream https://github.com/Homebrew/brew.git
  1. Create a feature branch:
git checkout -b feature-name
  1. Make changes and test:
bundle exec rake test
  1. Submit a pull request to the Homebrew repository

Troubleshooting

Common Issues and Solutions

1. Installation Failed

Problem: Installation script fails with permission errors Solution:

sudo chown -R $(whoami) /usr/local/Homebrew

2. Permission Denied

Problem: Commands fail with "Operation not permitted" Solution:

sudo chown -R $(whoami) /usr/local

3. Outdated Ruby

Problem: Ruby version too old for Homebrew Solution:

# macOS
brew install ruby

# Linux
sudo apt-get install ruby-full

4. Git Issues

Problem: Git authentication or connectivity problems Solution:

# Check Git configuration
git config --list

# Update Git
brew upgrade git

5. Network Issues

Problem: Unable to download packages Solution:

# Check network connectivity
ping github.com

# Use a different Git protocol
git config --global url."https://".insteadOf git://

6. Audit Failures

Problem: brew audit shows many issues Solution:

# Run with more details
brew audit --strict --display-cop-names

# Fix common issues
brew style --fix

Getting Help

  1. Documentation:
brew help
man brew
  1. Online Resources:
  1. Community Support:

Performance Tips

  1. Use a faster mirror:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
  1. Disable analytics:
brew analytics off
  1. Clean up old packages:
brew cleanup
  1. Use parallel downloads:
export HOMEBREW_MAKE_JOBS=4