[laravel] How to remove a package from Laravel using composer?

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?

This question is related to laravel laravel-4 package composer-php uninstallation

The answer is


Simpliest and Easiest way

Syntax:

composer remove <package>

Example:

composer remove laravel/tinker

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 .


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.


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

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

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


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


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


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.


  1. Remove package folder from vendor folder (Manual delete)
  2. remove it from 'composer.json' & 'composer.lock' files
  3. remove it from 'config/app.php' & 'bootstrap/cache/config.php' files
  4. composer remove package-name
  5. php artisan cache:clear & php artisan config:clear

**

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

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.


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


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.


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.


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


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.


Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to laravel-4

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration 'Malformed UTF-8 characters, possibly incorrectly encoded' in Laravel Can I do Model->where('id', ARRAY) multiple where conditions? how to fix stream_socket_enable_crypto(): SSL operation failed with code 1 Rollback one specific migration in Laravel How can I resolve "Your requirements could not be resolved to an installable set of packages" error? Define the selected option with the old input in Laravel / Blade Redirect to external URL with return in laravel laravel the requested url was not found on this server

Examples related to package

ModuleNotFoundError: No module named 'sklearn' Python: How to pip install opencv2 with specific version 2.4.9? Relative imports - ModuleNotFoundError: No module named x Is __init__.py not required for packages in Python 3.3+ "pip install unroll": "python setup.py egg_info" failed with error code 1 Unable to Install Any Package in Visual Studio 2015 beyond top level package error in relative import How can I specify the required Node.js version in package.json? "installation of package 'FILE_PATH' had non-zero exit status" in R Error in installation a R package

Examples related to composer-php

Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted How to change PHP version used by composer PHP7 : install ext-dom issue PHP error: "The zip extension and unzip command are both missing, skipping." Composer: file_put_contents(./composer.json): failed to open stream: Permission denied require(vendor/autoload.php): failed to open stream How to install a specific version of package using Composer? Composer update memory limit Cannot create cache directory .. or directory is not writable. Proceeding without cache in Laravel To enable extensions, verify that they are enabled in those .ini files - Vagrant/Ubuntu/Magento 2.0.2

Examples related to uninstallation

How to uninstall Eclipse? How to remove docker completely from ubuntu 14.04 How to completely uninstall kubernetes How to uninstall Anaconda completely from macOS How to Completely Uninstall Xcode and Clear All Settings Remove composer How can I find the product GUID of an installed MSI setup? How to uninstall mini conda? python Force uninstall of Visual Studio How to remove a package from Laravel using composer?