492

What is the correct way to remove a package from Laravel using composer? So far I've tried:

  1. Remove declaration from composer.json (in "require" section)
  2. Remove any Class Aliases from 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?

Nyk
  • 61
  • 9
igaster
  • 10,005
  • 4
  • 21
  • 25

19 Answers19

778

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

Updates

  • 26/10/2020 - Updated answer to assert command works for v1.x and v2.x of Composer
steadweb
  • 10,522
  • 2
  • 21
  • 34
  • 14
    @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 – zarax Apr 26 '17 at 14:05
  • 12
    `composer remove packagename` , It updates removing package from composer.json and removes package folder from vendor... laravel - 5.4.24, composer - 1.4.2. –  Jun 09 '17 at 11:18
  • It seems like composer is automatically installing missing packages after running `composer remove `. Anyway to avoid that? Using version 1.7.2. – Olle Härstedt Aug 31 '18 at 12:50
  • 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. – prashant Sep 13 '19 at 10:01
  • If you don't want your packages to be updated after removing a module you can run `composer install` instead of `composer update` – Gezzasa Jul 13 '20 at 10:15
  • @prashant `vendor` here is also a variable. For example, if you were removing Carbon, you would run `composer remove nesbot/carbon`. In this example, `nesbot` is the name of the vendor. – Charles Wood Mar 09 '21 at 19:17
185

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

  1. Remove declaration from composer.json (in "require" section)
  2. Remove Service Provider from config/app.php (reference in "providers" array)
  3. Remove any Class Aliases from 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 Vendor folder

Mostafa Norzade
  • 1,059
  • 2
  • 17
  • 35
igaster
  • 10,005
  • 4
  • 21
  • 25
66

Running the following command

composer remove Vendor/Package Name

That's all. No need composer update. Vendor/Package Name is just directory as installed before

Saularis
  • 389
  • 4
  • 13
Riaj Ferdous
  • 733
  • 6
  • 5
47

Normally composer remove used like this is enough:

$ composer remove vendor/package

but if composer package is removed and 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

$rm bootstrap/cache/config.php

And this is Laravel 5.6 I'm talking about, not some kind of very old stuff.

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

Yevgeniy Afanasyev
  • 27,544
  • 16
  • 134
  • 147
35

you can remove any package just by typing follwing command in 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
Shahrukh Anwar
  • 2,004
  • 1
  • 18
  • 20
20

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

php artisan cache:clear  
php artisan config:clear 

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

Raj
  • 1,596
  • 1
  • 18
  • 38
Rayees Pk
  • 1,347
  • 18
  • 16
19

Simpliest and Easiest way

Syntax:

composer remove <package>

Example:

composer remove laravel/tinker
gecko
  • 1,081
  • 2
  • 9
  • 25
18

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

Prashant Barve
  • 3,585
  • 2
  • 29
  • 40
15

If you are still getting the error after you have done with all above steps, go to your projects bootstrap->cache->config.php remove the provider & aliases entries from the cached array manually.

Bugs
  • 4,356
  • 9
  • 30
  • 39
Ramjith Ap
  • 193
  • 2
  • 5
  • This helped me. – Peter Griffin Jun 01 '18 at 07:57
  • 1
    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. – Samrat Khan Nov 12 '18 at 19:18
12

**

use "composer remove vendor/package"

** This is Example: Install / Add Pakage

composer require firebear/importexportfree

Uninsall / Remove

composer remove firebear/importexportfree

Finaly 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
SUNNETmedia
  • 311
  • 3
  • 5
10

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

composer remove <package_name>
composer update
Angel F Syrus
  • 1,607
  • 7
  • 18
  • 36
Maneesha
  • 101
  • 1
  • 2
  • If you are using `composer update` to remove package folder, it is not necessary as package source directory is deleted during the removal process. – Gucu112 Aug 06 '20 at 05:45
9

To remove a package using composer command

composer remove <package>

To install a package using composer command

composer require <package>

To install all packages which are mentioned in composer.json

composer install

To update packages

composer update

I used these for Laravel project

Kiran Reddy
  • 634
  • 11
  • 26
8

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

DonJoe
  • 1,195
  • 1
  • 8
  • 22
4

Remove the package with

composer remove vendorname/packagename

you can check remove package from composer.json - docs

Or you can remove the package name from composer.json file and run composer update from within your project directory. I hope it helps.

Abdellah Ramadan
  • 325
  • 2
  • 13
3

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 complete package name then you can open your project folder and go to composer.json file and check name in require an 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 "fideloper/proxy" package.

Step 2: Open command prompt with your project root folder directory enter image description here Step 3: First of all clear all cache by following commands. Run 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 your package is removing.

Sumit Kumar Gupta
  • 1,429
  • 15
  • 17
2

On laravel 8.* I following steps work for me :

  1. Run command composer remove package-name on terminal

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

  3. Remove related file from Config folder.

Remove from your code where you used .

infomasud
  • 448
  • 3
  • 7
2
  1. Remove package folder from vendor folder (Manual delete)
  2. remove it from 'composer.json' & 'composer.lock' files (use ctrl+f5 to search )
  3. remove it from 'config/app.php' & 'bootstrap/cache/config.php' files
  4. run this commads:
    • composer remove your-package-name
    • php artisan cache:clear & php artisan config:clear
Ahkmy990
  • 31
  • 4
0

There are quite a few steps here:

  1. Go to 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 this 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.

Chandraarnav
  • 21
  • 1
  • 10
  • 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. – Jason Aller Aug 20 '20 at 23:24
  • 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. – Chandraarnav Aug 21 '20 at 05:19
0

To add the packages command be like:

composer require spatie/laravel-permission

To remove the packages command be like:

composer remove spatie/laravel-permission
Aman Mehra
  • 11
  • 4