composer remove (uninstall) all installed packages (composer install rollback)

composer remove (uninstall) all installed packages (composer install rollback)

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why composer remove * Fails and How to Properly Rollback an Installation

When you run composer install, Composer reads your composer.json and generates a composer.lock file that pins specific versions of every dependency. If you need to roll back to the state before that installation—keeping only the lock file and configuration—you are essentially asking Composer to uninstall everything while ignoring the dependency graph constraints it normally enforces.

The most intuitive command, composer remove *, fails immediately with an [UnexpectedValueException] stating that "LICENSE" is not a valid alias. This isn't a bug; it's a parsing issue. The asterisk (*) in this context is interpreted as a wildcard for the package name itself, but Composer expects the format vendor/package. When you pass just *, or even */ *, Composer tries to resolve these as specific package identifiers rather than a blanket selection of all entries in the lock file. Furthermore, composer remove operates strictly against the requirements defined in composer.json. If your JSON file is empty or doesn't list the packages you wish to remove, Composer has no instruction to uninstall them, leading to warnings about packages like bin/console that are no longer required but weren't explicitly targeted for removal.

Attempting to loop through every package using composer show and piping it into a for loop is technically feasible but fragile. The command:

for package in $(composer show | awk '{print $1}'); do composer remove --no-interaction --dev --no-install "$package"; done

runs into significant roadblocks because Composer refuses to uninstall packages that are hard dependencies of others. You will frequently encounter the message: Removal failed, doctrine/annotations is still present, it may be required by another package. While you can bypass this with flags like --with-all-dependencies, doing so recursively for every single package in your stack often results in an endless cascade of removals that might delete core project files or leave the environment in a broken state.

If your goal is strictly to revert the vendor directory and restore the pre-installation state without touching composer.lock or composer.json, you must bypass Composer's uninstall logic entirely. The most direct approach is to treat the vendor directory as an artifact generated by a previous build step rather than a configuration state to be managed by Composer commands.

The safest, single-command equivalent to "rollback" in this specific scenario is simply deleting the directory:

rm -rf vendor/

This action removes all downloaded packages, scripts, and class maps without triggering Composer's dependency resolver or parsing your composer.lock file. The lock file remains untouched, preserving the exact versions you intended to pin for future runs. If you run composer install again afterward, Composer will regenerate the vendor directory based strictly on the current contents of composer.json and composer.lock.

This method respects the separation between build artifacts (vendor/) and configuration files (composer.json, composer.lock). It is the standard practice for CI/CD pipelines where you might want to verify that a project builds from scratch using only the defined requirements, without carrying over state from a previous installation. If you are working on a Laravel project, this approach ensures that your environment is reset to match the version constraints defined in your lock file, preventing conflicts caused by leftover files from manual composer remove attempts.

If you require a more granular control where you want to keep some packages but not others, you must edit composer.json to remove the unwanted entries and then run composer install. However, for a full rollback to the state of "files only," deleting the vendor directory is the precise, atomic operation that achieves your goal without side effects.

Our network