704

What is the correct way to remove a package from Laravel using PHP Composer?

So far I've tried:

  1. Remove declaration from file composer.json (in the "require" section)
  2. Remove any class aliases from file app.php
  3. Remove any references to the package from my code :-)
  4. Run composer update
  5. Run composer dump-autoload

None of these options are working! What am I missing?

Md. Suman Kabir
5,4515 gold badges29 silver badges45 bronze badges
asked Apr 17, 2014 at 6:59
1
  • "None of these options are working!" - why not? What exactly is not working when you remove the package from composer.json and run composer update? Commented Jan 15 at 15:31

20 Answers 20

1151
Answer recommended by PHP Collective

Composer 1.x and 2.x

Running the following command will remove the package from vendor (or wherever you install packages), composer.json and composer.lock. Change vendor/package appropriately.

composer remove vendor/package

Obviously you'll need to remove references to that package within your app.

I'm currently running the following version of Composer:

Composer version 1.0-dev (7b13507dd4d3b93578af7d83fbf8be0ca686f4b5) 2014年12月11日 21:52:29

Documentation

https://getcomposer.org/doc/03-cli.md#remove-rm-uninstall

Updates

  • 18/10/2024 - Updated URL to remove-rm-uninstall documentation
  • 27/12/2023 - Fixed URL to remove-rm documentation
  • 26/10/2020 - Updated answer to assert command works for v1.x and v2.x of Composer
answered Dec 12, 2014 at 9:09
Sign up to request clarification or add additional context in comments.

7 Comments

@ZeshanKhattak composer update will update all dependencies. It way leave the project in unstable state. Don't use composer update unless you want to update dependencies
composer remove packagename , It updates removing package from composer.json and removes package folder from vendor... laravel - 5.4.24, composer - 1.4.2.
It seems like composer is automatically installing missing packages after running composer remove <package>. Anyway to avoid that? Using version 1.7.2.
it should be: composer remove package_name instead: composer remove vendor/package there is no need of vendor as laravel automatically check in vendor directory for packages.
If you don't want your packages to be updated after removing a module you can run composer install instead of composer update
|
217

I got it working... The steps to remove a package from Laravel are:

  1. Remove the declaration from file composer.json (in the "require" section)
  2. **Remove Service Provider from file config/app.php (reference in the "providers" array)
  3. Remove any class aliases from file config/app.php
  4. Remove any references to the package from your code :-)
  5. Run composer update vendor/package-name. This will remove the package folder from the vendor folder and will rebuild the Composer autoloading map.
  6. Manually delete the published files (read the comment by zwacky)

It will remove the package folder from the Vendor folder.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Apr 17, 2014 at 7:17

4 Comments

although unpublishing assets/configs isn't really an automated thing. i usually delete manually the vendor/package folders in config/ or public/.
now laravel should come up with something like "remove package <package-name>" to make it easier.
A problem with this solution is that it will update all other packages, which may not be what you want.
(1) and (5) can be replaced with running composer remove vendor/package, I think.
65

Normally composer remove used like this is enough:

composer remove vendor/package

But if a Composer package is removed and the "config" cache is not cleaned you cannot clean it. When you try like so

php artisan config:clear

you can get an error In ProviderRepository.php line 208:

Class 'Laracasts\Flash\FlashServiceProvider' not found

This is a dead end, unless you go deleting files:

Laravel 5.6

rm bootstrap/cache/config.php

Laravel 9

rm bootstrap/cache/packages.php

It happens usually on automated deployment, when you copy files of a new release on top of old cache. Even if you cleared the cache before copying. You end up with an old cache and a new composer.json file.

answered Sep 16, 2018 at 23:23

3 Comments

With 5.6, my bootstrap/cache was empty. I forgot that I'd changed the cache path (config/cache.php)! Deleting the files in the new cache folder fixed the problem!
@YevgeniyAfanasyev This is not fixed Even in 5.7
I almost spent 3 hours pulling my hairs out over this. I thought config:clear would fix this.
42

You can remove any package just by typing the following command in the terminal, and just remove the providers and alias you provided at the time of installing the package, if any and update the composer,

composer remove vendor/your_package_name
composer update
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Mar 15, 2018 at 11:02

1 Comment

Sometimes to update the new dependancies, you have to update the composer. I think there is no harm in running that.
28

Running

composer remove package/name
php artisan optimize:clear

e.g "Composer remove mckenziearts/laravel-notify" works for me while using Laravel 8.

answered Oct 4, 2021 at 11:24

Comments

28

You can do any one of the below two methods:

  1. Running the below command (most recommended way to remove your package without updating your other packages)

    $ composer remove vendor/package

  2. Go to your composer.json file and then run command like below it will remove your package (but it will also update your other packages)

    $ composer update

  3. Also need to run this command for clearing cache, config etc.

    $ php artisan optimize:clear

kaamrul
631 silver badge8 bronze badges
answered Jan 6, 2018 at 9:41

Comments

23

Before removing a package from a composer.json declaration, please remove the cache:

php artisan cache:clear 
php artisan config:clear 

If you forget to remove the cache and you get a "class not found error" then please reinstall the package, clear the cache and remove again.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 31, 2018 at 14:24

Comments

18

If you are still getting the error after you are done with all the steps in the previous answers, go to your projects, BootstrapCacheconfig.php. Remove the provider and aliases entries from the cached array manually.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Oct 6, 2017 at 7:40

2 Comments

This helped me.
Some package vendor does not meet all requirements to create a package. For that reason, these vendors composer remove vendor/package unable to remove the cache entries properly. So, @Ramjith Ap is absolutely correct here.
17

Use:

composer remove vendor/package

This is an example:

Install or add a package

composer require firebear/importexportfree

Uninstall / remove

composer remove firebear/importexportfree

Finally after removing:

php -f bin/magento setup:upgrade
php bin/magento setup:static-content:deploy –f
php bin/magento indexer:reindex
php -f bin/magento cache:clean
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Feb 20, 2019 at 6:47

Comments

16

To add the packages, the command is to be like:

composer require spatie/laravel-permission

To remove the packages, the command is to be like:

composer remove spatie/laravel-permission
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered May 24, 2021 at 19:12

1 Comment

Omg, I was looking for composer remove command to remove exactly this package.
10

In case the given answers still don't help you remove that, try this:

  • Manually delete the line in require from composer.json

  • Run composer update

answered Jun 10, 2018 at 15:22

Comments

7

If this doesn't work "composer remove package/name", you can still remove it manually.
Note : package/name is like spatie etc.

  1. Go to composer.json and find the package name
  2. Delete package name from composer.json
  3. Find the vendor file in your Laravel project.
  4. Delete the package file which is under vendor
  5. run composer install on your terminal

Note : Package File mean is that package that you are looking for. For example, you want to remove Spatie. Then you need to find that with similar name in vendor file and you need to delete it manually.
Your package was removed successfully.

Ryan M
20.6k35 gold badges74 silver badges85 bronze badges
answered Aug 24, 2021 at 11:55

5 Comments

What is that "package file"? Do you mean composer.lock? You forgot to add the consequences that deleting the lock file cuases, like updating other dependencies
For example, you have a package named as spatie. You will find it under vendor file. composer.json. All installed package will be starage under Vendor with package's name.
What do you mean by "remove Spatie"? That's not a package. Also, composer remove does all this automatically
Spatie is an example package name. It's a permission management package for Laravel. I just gave it as an example. @NicoHaase Sometimes composer remove doesn't work and we need to remove it manually. It's another solution to this problem.
Please add all clarification to your answer by editing it
6

You have two solution:

  • Either remove of composer.
composer remove *your_package_name*
  • Or delete the line in require from composer.json and then run update
composer update

After removed, recommend to run the below two commands.

php artisan cache:clear
php artisan config:clear
Emad Kerhily
7421 gold badge5 silver badges23 bronze badges
answered Feb 4, 2023 at 7:38

Comments

5

To remove any package in your Laravel project you only need to execute the below command using Composer.

composer remove {packageName}

eg: composer remove maatwebsite/excel In this command, we are removing maatwebsite/excel package.

answered Feb 16, 2024 at 10:49

Comments

4

We have come with a great solution. This solution is practically done in Laravel 6. If you want to remove any package from your Laravel Project then you can easily remove the package by following below steps:

Step 1: You must know the package name which you want to remove. If you don't know the complete package name then you can open your project folder and go to the composer.json file and check the name in the require array:

"require": {
 "php": "^7.2",
 "fideloper/proxy": "^4.0",
 "laravel/framework": "^6.2",
 "laravel/passport": "^8.3",
 "laravel/tinker": "^2.0"
 },

Suppose, here I am going to remove the "fideloper/proxy" package.

Step 2: Open a command prompt with your project root folder directory

Enter image description here

Step 3: First of all, clear all cache by the following commands. Run the commands one by one.

php artisan cache:clear 
php artisan config:clear 

Step 4: Now write the following command to remove the package. Here you need to change your package name instead of my example package.

composer remove fideloper/proxy

Now, wait for a few seconds while your package is removed.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Feb 3, 2020 at 21:33

1 Comment

or composer remove laravel/telescope --dev if it is dev package
4

On Laravel 8.*, the following steps work for me:

  1. Run command composer remove package-name on the terminal

  2. Remove Provider and aliases from file Config/app.php

  3. Remove the related file from the Config folder.

Remove it from your code where you used it.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 24, 2021 at 22:20

1 Comment

I have been trying this but i continuously get an error : ` In ProviderRepository.php line 208: class xxxxxx not found`
3
  1. Remove the package folder from the vendor folder (manual delete)
  2. Remove it from file composer.json and 'composer.lock' files (use Ctrl + F5 to search)
  3. Remove it from file config/app.php and file bootstrap/cache/config.php files
  4. Run these commands:
    composer remove **your-package-name**
    php artisan cache:clear
    php artisan config:clear
    
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 27, 2021 at 13:14

1 Comment

Please never recommend that anybody should edit the composer.lock manually. Calling composer remove is enough, as this removes the package from the vendor folder, and from both composer files
0

There are quite a few steps here:

  1. Go to file composer.json and look for the package and how it is written over there.
  • for example

{ "require": { "twig/twig": "^3.0" } }

I wish to remove twig 3.0

  1. Now open cmd and run composer remove vendor/your_package_name as composer remove twig/twig will remove the package.

  2. As a final step, run composer update. This will surely give you a massage of nothing to install or update, but this is important in case your packages have inter-dependencies.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Aug 20, 2020 at 18:52

3 Comments

When adding an answer to six year old question with an accepted answer and fifteen existing answers it is important to point out what new aspect of the question your answer addresses.
The most important thing I faced is point No.3, which we often ignore as we usually get "nothing to install or update", I was unfortunate while uninstalling certain illuminate component as I had sentinel which uses illuminate capsule. however thankfully update composer command helped here. the answers above misses on the inter-dependencies part, in case you feel its not important juss reply back I will remove my answer.
Calling composer update is not needed if you just want to remove a package
0

You can simply do composer remove { name of the package here }

answered Sep 1, 2024 at 19:19

Comments

-1

To remove a package from your Laravel project using Composer, follow these steps:

  1. Run the Composer Remove Command Open your terminal and run the following command:

    composer remove vendor/package-name

Example: If you want to remove the guzzlehttp/guzzle package, run:

composer remove guzzlehttp/guzzle
  1. Clear Cache (Optional) After removing the package, it's good practice to clear Composer's cache:

    composer clear-cache

  2. Remove Unused Dependencies (Optional) If there are unused dependencies, you can clean up by running:

    composer install composer update --no-dev

  3. Remove References from Config and Code (If Necessary) Check your config/app.php for any service provider or alias related to the package and remove it. Remove any use statements or dependencies in your controllers, models, or services. If the package has published assets (like migrations or config files), remove them manually.

  4. Dump Autoload (Optional) To refresh Composer's autoload files, run:

    composer dump-autoload

  5. Restart Your Server (If Required) If your Laravel application is running, restart it to apply the changes.

Now, your Laravel project should no longer include the removed package! 🚀

answered Mar 6 at 5:17

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.