How to remove a package from PHP composer?

PHP Composer is a package manager designed to install the libraries or dependencies required by a PHP application or project. It is created for helping PHP developers to streamline their work on complex projects by simplifying the management of external libraries and packages. Further, they can also define and install libraries on which their code relies on, as well as track updates for those libraries.

Not only this it makes collaboration easy and allows multiple developers to work on the same software without running into conflicts due to incompatible library versions. Hence, instead of managing dependencies manually, with this PHP package manager developers can focus on writing their complex codes.

All the major PHP frameworks such as Symfony, Laravel, and Zend are supported by PHP-Composer. Hence, it is an important tool in the PHP development process to improve the efficiency of PHP projects.

Steps to remove a package from PHP Composer

The commands given here to uninstall the packages using Composer will work on all operating systems such as Windows, Linux, and macOS.

List the install packages

If you are not sure what packages you have installed using PHP-Composer, then we can list them. For that on your command terminal first, navigate to your project’s directory and then type the following command:

composer show --installed

This will show you a list of all the packages that are currently installed in your project.

List installed php composer packages 1

Uninstall Composer-installed packages

If you don’t know the exact name of the package you want to remove, then go through the list and identified it or them.

Once you have the package list, use the following command syntax to remove any of them:

composer remove my-package

Note: Replace “my package” with the actual name of the package that you want to remove.

For example:

composer remove phpunit/phpunit

That’s it, after executing the above command with the package name you are interested in removing, it will uninstall it from your system along with all dependencies required by it, from your project.

remove php composer installed package 1

Update Composer Lock FIle

Although, it is not necessary because PHP-Composer will automatically update the Lock file after uninstalling a package. Well, the composer.lock file comprises the specific versions of all the packages that were installed in your project. However, if it has not been updated then here is the command to do it manually.

composer update --lock

This will update the composer.lock file to reflect the changes you made by removing the package.

So, this was the quick way to clean and optimize your Composer environment for a project, if some packages are not required by it anymore.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.