MacOs change default php version with Homebrew

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Migrating PHP Versions on macOS with Homebrew: A Developer's Guide As developers working within the robust ecosystem of PHP, managing different versions is often a necessity for project compatibility and staying up-to-date with modern features. On macOS systems, especially those running older versions like Catalina, switching the default PHP executable can seem straightforward, but it often involves navigating the intricacies of Homebrew’s symlinking system. This post dives into the specific scenario you encountered: attempting to switch the default `php` command from version 7.4 installed by default to PHP 8.0 using Homebrew. We will analyze why the initial attempt failed and provide the definitive, developer-approved method for achieving this migration cleanly. ## The Challenge: Symlinks and Default Executables When you install multiple PHP versions via Homebrew (e.g., `php@7.4` and `php@8.0`), Homebrew installs them into separate directories within `/usr/local/Cellar`. To make one version the system default, you rely on symbolic links (symlinks) managed by the generic `php` command pointing to the desired version. Your attempt using `brew link --overwrite --force php@8.0` failed or produced ambiguous results because the existing symlink for `php` was already pointing to a valid installation, leading to conflicts rather than an automatic switch. The output you received confirms this: Homebrew warned that it had to unlink and relink, indicating a manual intervention is required to correctly manage which version the shell finds first when executing `php`. ## The Solution: Correctly Managing PHP Links The key to successfully switching the default executable lies in explicitly unlinking the old version and then linking the desired new version as the primary link. We need to ensure that the generic `php` command points exactly where we intend it to point, which is often achieved by managing the links within the Homebrew structure carefully. Here is the robust sequence of commands to properly migrate your system default: ### Step 1: Unlink the Existing Default (Optional but Recommended) First, ensure that any lingering links are cleaned up before introducing the new version. ```bash brew unlink php ``` ### Step 2: Link the Desired Version as the New Default Now, link the desired version (`php@8.0`) to the generic `php` command. Using `--overwrite