How to Install Composer with Brew: Quick Start Guide

Updated

Homebrew package manager on macOS

brew install composer, then check it:

$ brew install composer
==> Pouring composer--2.10.2.arm64_tahoe.bottle.tar.gz
🍺  /opt/homebrew/Cellar/composer/2.10.2: 4 files, 3.7MB

$ composer --version
Composer version 2.10.2 2026-07-01 11:24:45
PHP version 8.5.8 (/opt/homebrew/Cellar/php/8.5.8/bin/php)

Two things to know before you run it. First, the formula depends on Homebrew’s own PHP — brew info composer reports Required (1): php — so on a machine without it, this command installs a second PHP alongside whatever you already use (Herd, MAMP, php@8.4). In the output above, php 8.5.8 was already installed, so only Composer itself was poured. Second, Homebrew’s bin usually precedes other PHP tooling on PATH, so the new binary takes over:

$ which -a composer
/opt/homebrew/bin/composer
/Users/[user]/Library/Application Support/Herd/bin/composer

It is the same file the official installer gives you

This is worth knowing because it settles the “which method is more trustworthy” question. I ran the official installer, with the sha384 verification step getcomposer.org itself prescribes, and compared the result to the bottled binary:

$ EXPECTED=$(curl -sS https://composer.github.io/installer.sig)
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "echo hash_file('sha384','composer-setup.php');"
expected: c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47
actual:   c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47
MATCH

$ php composer-setup.php --install-dir=. --filename=composer.phar
$ shasum -a256 composer.phar /opt/homebrew/opt/composer/bin/composer
5ee7125f8a30a34d246cefdc0bc85b8a783b28f2aec968994118512350d28027  composer.phar
5ee7125f8a30a34d246cefdc0bc85b8a783b28f2aec968994118512350d28027  /opt/homebrew/opt/composer/bin/composer

Byte for byte identical. Use whichever you prefer — but if you use the manual route, do the hash comparison. Appending two bytes to the downloaded installer changes the digest completely, which is exactly the tampering the check is there to catch. Guides that print php -r "copy(...)"; php composer-setup.php with no verification step are telling you to execute an unauthenticated remote script.

The self-update conflict, and what actually happens

composer self-update does not refuse or fail on a Homebrew install. It succeeds, and quietly overwrites the file Homebrew is managing:

$ composer self-update 2.10.1
Upgrading to version 2.10.1 (stable channel).
Use composer self-update --rollback to return to version 2.10.2

The file inside the Cellar is now a different binary from the one Homebrew poured, even though it is marked read-only (-r-xr-xr-x) — Composer replaces the file rather than writing through it, and the directory is user-owned:

$ shasum -a256 /opt/homebrew/Cellar/composer/2.10.2/bin/composer
345b9c6a98da5c30dcbd4b0d99fc8710bf0ae98a3898eea18f7b2ad9dec93f06     # was 5ee7125f...

From here the two tools disagree, and nothing tells you:

$ composer --version
Composer version 2.10.1 2026-06-04 10:25:59

$ brew list --versions composer
composer 2.10.2

$ brew upgrade composer
Warning: composer 2.10.2 already installed

brew upgrade compares its own recorded version against the formula and concludes there is nothing to do — so the desync survives every future brew upgrade. brew doctor does not catch it either: with the Cellar file replaced, its full 51-line output contained zero mentions of Composer. You can sit on a Composer version Homebrew believes it removed for as long as you like, which is a real problem when the reason you downgraded, or the reason you need to upgrade, is a security fix.

Fixing a desynchronised install

$ brew reinstall composer
🍺  /opt/homebrew/Cellar/composer/2.10.2: 4 files, 3.7MB

$ composer --version
Composer version 2.10.2 2026-07-01 11:24:45

$ shasum -a256 /opt/homebrew/opt/composer/bin/composer
5ee7125f8a30a34d246cefdc0bc85b8a783b28f2aec968994118512350d28027     # back to the poured bottle

composer self-update --rollback also returns you to the previous binary, but brew reinstall is the one that restores the exact file Homebrew expects. The rule is simple: if Homebrew installed it, Homebrew updates it. Run brew upgrade composer, never composer self-update. If you want to manage Composer versions yourself — pinning an old release to reproduce a bug, or tracking the preview channel — install the phar manually into ~/.local/bin and leave the Homebrew formula out of it, rather than fighting over one file.

brew update is optional, and Composer depends on Homebrew’s PHP

brew update is not a prerequisite step: this Homebrew (6.0.16) refreshes its own package index before an install on a timer — its env_config.rb documents HOMEBREW_AUTO_UPDATE_SECS with a default of 86400 seconds and HOMEBREW_NO_AUTO_UPDATE to turn the behaviour off, and Homebrew’s published manual gives the same default: 86400 (24 hours). Running brew update first is harmless, just not a step.

Composer’s PHP dependency is the single most common surprise: people with an existing PHP setup run brew install composer and find themselves with an extra PHP and a composer pointing at it. That is what the second line of composer --version is telling you — the PHP path it will use for every composer install you run.

Once Composer is working, creating a Laravel project is one further command, and checking which framework version you ended up with is worth doing straight afterwards.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.