Skip to content

Composer caches every package version, and vendor folders repeat them

The global cache plus a vendor folder per project means the same library many times over. What to clear and what to leave.

4 min read

Composer has the same shape as every other package manager: a global cache of what it downloaded, and a full copy inside each project. The difference is that PHP projects tend to be numerous and long lived, so the copies add up quietly.

The two halves

composer config --global --list | grep cache-dir
du -sh ~/.composer ~/Library/Caches/composer 2>/dev/null
find ~ -maxdepth 5 -type d -name vendor 2>/dev/null \
  -exec du -sh {} + | sort -h | tail -15

The global cache holds downloaded archives and repository metadata. Each vendor folder is a full extraction of everything that project needs, and a framework project's vendor directory is routinely hundreds of megabytes.

Clearing them

CommandRemovesCost
composer clear-cacheThe global download cacheRedownload on next install
Deleting a vendor folderOne project's dependenciescomposer install restores it
composer install --no-devDev dependencies, in deploymentNot for a working machine

Both are safe as long as composer.lock is present, which pins exact versions. With the lock file, reinstalling gives you exactly what you had; without it, you get whatever resolves today, which is a different and less comfortable proposition.

The bulk removal that is worth doing

find ~ -maxdepth 5 -type d -name vendor -mtime +180 2>/dev/null \
  -exec du -sh {} + | sort -h | tail -20

That lists vendor folders untouched for six months. Those belong to projects you are not working on, and composer install brings them back in a minute when you return.

Checking the lock file first

ls composer.lock 2>/dev/null || echo 'no lock file, be careful'

A project without a lock file is the one case to leave alone, because reinstalling may not reproduce the same versions. It is the same rule as CocoaPods and Podfile.lock, and it applies across every ecosystem.

Common questions

Where is the Composer cache on a Mac?

Usually ~/.composer or ~/Library/Caches/composer, depending on version and configuration. Run composer config --global --list and look for cache-dir to see the exact path.

Is it safe to delete a vendor folder?

Yes, when composer.lock is present, because composer install restores exactly the pinned versions. Without a lock file, reinstalling may resolve different versions.

How do I clear the Composer cache?

Run composer clear-cache, which empties the global download cache. The next install redownloads what it needs, so the cost is bandwidth and time.

Why do PHP projects use so much disk space?

Because each project keeps a full vendor directory, and framework projects pull in hundreds of packages. Ten projects means ten copies of much the same set of libraries.

Read next