How to Install Specific Homebrew Formula Versions

Learn how to install specific versions of Homebrew formulas like PostgreSQL 8.4.4 instead of the latest version. Complete guide with step-by-step instructions and best practices.

How do I install a specific version of a formula in Homebrew? For example, how can I install postgresql-8.4.4 instead of the latest version 9.0?

To install a specific version of a Homebrew formula, you can use the @version syntax followed by the formula name, or use the brew command with version pinning options. For PostgreSQL specifically, you would run brew install postgresql@8.4 where 8.4 represents the major version you want to install, and Homebrew will automatically find and install the appropriate patch version available in the repository.

Contents

Understanding Homebrew Version Management

Homebrew, the popular package manager for macOS, provides several mechanisms for managing different versions of software packages. When you install a formula, Homebrew typically downloads and installs the latest stable version available in its repositories. However, there are legitimate reasons you might need a specific version:

  • Compatibility: Your application or project requires a specific version
  • Stability: You want to avoid breaking changes in newer versions
  • Testing: You need to test against different versions
  • Legacy Systems: You’re maintaining older systems that require specific versions

Homebrew handles version management through its core formula system and taps, which are essentially repositories of formulas. Understanding how versions are organized is key to successfully installing specific versions.

Version Naming Conventions

Homebrew uses specific naming conventions for versioned formulas:

  • Standard versioning: postgresql@8.4, python@3.8
  • Pin syntax: postgresql@8.4.4
  • Tap formulas: some/tap/formula@version

The @ symbol is crucial for versioned formulas, as it tells Homebrew you’re referencing a specific version rather than the default formula.


Methods for Installing Specific Formula Versions

There are multiple approaches to installing specific versions of formulas in Homebrew, each suited for different scenarios.

Method 1: Using the @version Syntax

The most straightforward method is to append @version to the formula name:

bash
brew install postgresql@8.4

This command tells Homebrew to install the PostgreSQL formula specifically for version 8.4. Homebrew will automatically select the latest patch version available (e.g., 8.4.4) within that major version line.

Method 2: Using brew install with Specific Version

For more precise control, you can specify the exact version number:

bash
brew install postgresql@8.4.4

This ensures you get exactly version 8.4.4, provided it’s available in the Homebrew repository.

Method 3: Using brew fetch and brew install

For maximum control, you can first fetch the formula and then install it:

bash
brew fetch postgresql@8.4.4
brew install postgresql@8.4.4

This two-step process allows you to verify what version will be installed before proceeding.

Method 4: Using brew pin to Lock Versions

Once installed, you can “pin” a version to prevent it from being automatically upgraded:

bash
brew pin postgresql@8.4

This creates a symbolic link that ensures Homebrew’s upgrade commands won’t modify this specific version.


PostgreSQL Version Installation Example

Let’s walk through a complete example of installing PostgreSQL 8.4.4 specifically, as requested in your question.

Step-by-Step Installation Process

  1. Check Available Versions
    First, verify what PostgreSQL versions are available:

    bash
    brew search postgresql
    

    This will show you all available PostgreSQL formulas, including versioned ones.

  2. List Available Specific Versions
    To see all available versions of PostgreSQL:

    bash
    brew info postgresql
    

    Look for output that shows different versions available, typically in the format:

    postgresql@8.4: stable 8.4.4 (bottled)
    postgresql@9.0: stable 9.0.22 (bottled)
    
  3. Install Specific Version
    Install the specific 8.4 version:

    bash
    brew install postgresql@8.4
    

    Homebrew will automatically download and install the latest patch version in the 8.4 series (which would be 8.4.4 if available).

  4. Verify Installation
    Check that the correct version was installed:

    bash
    postgres --version
    

    You should see output indicating PostgreSQL 8.4.x.

Alternative: Manual Version Selection

If you need even more precise control over the exact version, you can:

bash
# List all available versions
brew list-versions postgresql

# Install specific patch version
brew install postgresql@8.4.4

Service Management for Versioned PostgreSQL

When you install multiple versions of PostgreSQL, each version runs as a separate service:

bash
# Start PostgreSQL 8.4 service
brew services start postgresql@8.4

# Stop PostgreSQL 8.4 service
brew services stop postgresql@8.4

# Check status of all PostgreSQL services
brew services list | grep postgresql

Managing and Switching Between Versions

Once you have multiple versions installed, you’ll need strategies to manage and switch between them effectively.

Version Switching Workflow

To switch between different PostgreSQL versions:

bash
# Stop all PostgreSQL services
brew services stop postgresql@8.4
brew services stop postgresql@9.0

# Start the desired version
brew services start postgresql@8.4

Environment Configuration

Each versioned formula creates its own configuration and data directories:

bash
# PostgreSQL 8.4 data directory
/usr/local/var/postgres@8.4/

# PostgreSQL 9.0 data directory
/usr/local/var/postgres@9.0/

You can specify which version to use by setting appropriate environment variables in your shell configuration file:

bash
# In ~/.bashrc or ~/.zshrc
export PATH="/usr/local/opt/postgresql@8.4/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/postgresql@8.4/lib"
export CPPFLAGS="-I/usr/local/opt/postgresql@8.4/include"

Using Symlinks for Version Management

For more flexible version management, you can create symlinks:

bash
# Create symlink to specific version
ln -sf /usr/local/opt/postgresql@8.4/bin/postgres /usr/local/bin/postgres

# Verify the symlink points to correct version
which postgres
postgres --version

Troubleshooting Common Issues

When working with specific versions, you may encounter several common issues that need troubleshooting.

“No available formula” Errors

If you get an error like Error: No available formula with the name "postgresql@8.4.4", it means that exact version isn’t available. Try:

bash
# List available versions
brew search postgresql
brew info postgresql

# Install the closest available version
brew install postgresql@8.4

Dependency Conflicts

Different versions may have conflicting dependencies. To resolve this:

bash
# Clean up existing installations first
brew uninstall postgresql
brew cleanup

# Install specific version with all dependencies
brew install postgresql@8.4 --with-python --with-perl

Service Conflicts

If you have multiple versions running simultaneously, you may encounter port conflicts. Ensure only one version is active:

bash
# Check running services
brew services list

# Stop all PostgreSQL services
brew services stop postgresql

# Start only the desired version
brew services start postgresql@8.4

Data Directory Issues

Each PostgreSQL version needs its own data directory. When switching versions, you may need to initialize new databases:

bash
# Initialize data directory for specific version
initdb /usr/local/var/postgres@8.4 -E utf8

# Start the server with the correct data directory
pg_ctl -D /usr/local/var/postgres@8.4 -l logfile start

Best Practices for Version Pinning

When working with specific versions, following best practices will save you time and prevent issues.

Pinning Strategies

Temporary Pinning for testing:

bash
brew install postgresql@8.4
# Test your application
# Later...
brew upgrade postgresql@8.4

Permanent Pinning for production:

bash
brew install postgresql@8.4
brew pin postgresql@8.4

Documentation and Version Tracking

Maintain clear documentation of which versions are installed:

bash
# Create a version inventory file
brew list | grep postgresql > postgresql_versions.txt
brew info postgresql@8.4 >> postgresql_versions.txt

Regular Maintenance

Even with pinned versions, regular maintenance is important:

bash
# Update Homebrew itself
brew update

# Check for outdated formulas
brew outdated

# Update specific formula without upgrading pinned versions
brew upgrade postgresql@8.4

Cleanup and Housekeeping

Keep your Homebrew installation clean:

bash
# Remove old versions
brew cleanup

# Remove unused dependencies
brew autoremove

# Check for issues
brew doctor

Sources

  1. Homebrew Documentation - Formula Versions
  2. Homebrew GitHub Wiki - Versioning
  3. PostgreSQL Homebrew Formula
  4. Homebrew Services Management
  5. Homebrew Pinning Guide

Conclusion

Installing specific versions of Homebrew formulas is straightforward once you understand the @version syntax and available options. For PostgreSQL specifically, you can easily install version 8.4.4 by running brew install postgresql@8.4, which will automatically select the latest patch version in the 8.4 series.

Key takeaways:

  • Use @version syntax (e.g., postgresql@8.4) for major version installation
  • Pin versions with brew pin to prevent accidental upgrades
  • Each version runs as a separate service with its own data directory
  • Regular maintenance and documentation help manage multiple versions effectively

If you need to work with multiple versions regularly, consider creating shell aliases or scripts to streamline the version switching process. Remember that older versions like PostgreSQL 8.4 may not receive security updates, so use them only for compatibility reasons when necessary.

Authors
Verified by moderation
Moderation