Skip to content
Related Articles

Related Articles

How to remove unused dependencies from composer?
  • Difficulty Level : Easy
  • Last Updated : 27 Jan, 2021

Removing unused Dependencies from Composer is very easy. Following are the two approaches:

1. Using Composer Remove:This is the simplest command to remove unused Dependencies from Composer. 

Syntax:

composer remove dependency_name

Firstly decide which dependency you want to remove from the composer. Here we will be removing stripe/stripe-php dependency as shown below in the composer and the stripe folder is also present in the directory.

Dependencies in the composer.

Stripe folder is present before deleting.



Now just go to the directory in which your composer.json file is there and then type the below command:

composer remove stripe/stripe-php

composer remove stripe/stripe-php Command

Output: This command removed the stripe/stripe-php dependency from the composer as shown below:

Stripe folder removed after the command.

Thus, the composer remove is a very easy command and will remove the unused dependencies from the composer.

2. Using Composer Update:It’s another way of removing unused Dependencies from Composer. 

Syntax:

composer update 

Running composer update Command. 

The above command will update the complete directory and will add all the dependencies and folders shown below:

All the Folders Added and Updated.

Now just open the composer.json file and delete the dependency which you want to remove.

composer.json File Contents

Now just delete the phpunit/phpunit:4.6.1 dependency and the updated composer.json is shown below:

composer.json File after Deletion

Now we just need to run the composer update command once more and it will remove all the phpunit dependencies which we don’t want as shown below:

Running composer update once again.

Dependencies Removed 

“composer update” will do the task, but it will also update the other packages.

Now if you just want to remove a specific package without updating others then just specify that package name.

composer update packageauthor/package_name

It will remove the “package_name” package.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :