Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a package using composer (without updating other packages)

I've currently installed a package "watson/sitemap". Now, I want to remove it without using "composer update" since it will update other packages which I don't want.

Any help would be much appreciated.

like image 566
papski Avatar asked Oct 13 '17 03:10

papski


People also ask

How do I update a single package in composer?

To update your packages json file is. Run composer update (on your local machine) to update the required packages and re-generate a composer. lock file. Commit the updated composer.

Does composer install update packages?

composer update will update our dependencies as they are specified in composer. json . Supposing we have actually installed the 2.0. 1 version of the package, running composer update will cause an upgrade of this package (for example to 2.0.

How to get rid of unused packages in composer?

You could script this by using Composer's PHP classes or by parsing the composer.lock file, but this is a manual process you can follow. 1. Remove the unwanted package (s) 2. Look for orphaned dependencies composer show -N | xargs -n 1 composer why | grep "There is no installed package"

How to remove a package from Laravel using composer?

Removing a package from Laravel using composer. To remove a Laravel package, we just need to run a single command: composer remove spatie/laravel-sitemap Change the spatie/laravel-sitemap with the name of the package that you want to remove. This will remove the line from your compser.json file and also the files from the vendor folder.

How to remove stripe/Stripe-PHP dependency from composer?

Now just go to the directory in which your composer.json file is there and then type the below command: Output: This command removed the stripe/stripe-php dependency from the composer as shown below:

How to remove “Kartik-v/yii2-date-range” from composer?

Simply manually remove the “kartik-v/yii2-date-range”: “dev-master” line from the composer.json and save then run composer update in the terminal. In the terminal, just run this command after removing the extension information in the composer.json.


2 Answers

UPDATE: Composer 2 is now out, and it seems to be smart enough to handle the recursion. You need only remove the offending package.

I recently needed to do this. Here's a real-world example. This is pretty hacky. You could script this by using Composer's PHP classes or by parsing the composer.lock file, but this is a manual process you can follow.

1. Remove the unwanted package(s)

composer remove --no-update illuminate/mail
composer update illuminate/mail

2. Look for orphaned dependencies

composer show -N | xargs -n 1 composer why | grep "There is no installed package"

Output (something like this):

There is no installed package depending on "erusev/parsedown"
There is no installed package depending on "swiftmailer/swiftmailer"
There is no installed package depending on "tijsverkoyen/css-to-inline-styles"

3. Remove orphaned dependencies

composer update erusev/parsedown swiftmailer/swiftmailer tijsverkoyen/css-to-inline-styles

4. Rinse, repeat

Repeat steps 2 and 3 until you've found all the orphans.


Clarification: If you use the --no-update flag, you won't upgrade packages... however (as of writing, early 2020) it also does not remove orphaned dependencies. You're not telling it not to "upgrade". You're telling it not to update any of the installed (composer.lock) dependencies. Big difference. This is why you have to find them and manually "update" them out of your project.

like image 137
Derrek Bertrand Avatar answered Sep 28 '22 02:09

Derrek Bertrand


Right way:

composer remove watson/sitemap --no-update

From CLI Docs:

The remove command removes packages from the composer.json file from the current directory.

php composer.phar remove vendor/package vendor/package2

After removing the requirements, the modified requirements will be uninstalled.

Hack way:

Remove the entry from composer.json then run

composer update watson/sitemap

This will remove a package totally from composer.lock and /vendor

like image 25
Jonathan Solorzano Avatar answered Sep 28 '22 03:09

Jonathan Solorzano