How to remove the extension or package with composer
Home » BLOG » Yii2.0 framework » How to remove the extension or package with composer

How to remove the extension or package with composer

category:  Yii2.0 framework

Often when I work with the PHP framework and I want to install the extensions or packages in general term, in order to use in the framework, for PHP, we use composer. In js framework, you will use npm or yarn. To install the extensions, the third party(extension owner) page will let you know the installation composer command. But often they don’t provide you how to remove or uninstall the extensions. I will share this with you today.

When the extensions are installed, except the new folder will be created for that new extensions, the composer.json and composer.lock will be updated with new extensions information too. In order to remove the extension completely, I prefer to remove that extensions in composer.json and run the composer update in the terminal.

For example, in the composer.json, let says we want to remove the yii2-date-range extension. 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.

"require": {
    "php": ">=5.4.0",
    "yiisoft/yii2": "~2.0.6",
    "yiisoft/yii2-bootstrap": "~2.0.0",
    "yiisoft/yii2-swiftmailer": "~2.0.0",
    "dmstr/yii2-adminlte-asset": "2.*",
    "yiisoft/yii2-jui": "*",
    "wbraganca/yii2-dynamicform": "*",
    "kartik-v/yii2-mpdf": "dev-master",
    "miloschuman/yii2-highcharts-widget": "dev-master",
    "guzzlehttp/guzzle": ">=4.1.4 <7.0",
    "yiisoft/yii2-imagine": "^2.1",
    "kartik-v/yii2-date-range": "dev-master"
},

In the terminal, just run this command after removing the extension information in the composer.json. It may take a few minutes since the command may update other extensions in the composer.json as well.

composer update

That’s it.

Note:
The composer will update all extensions in the composer.json that have the newer extensions available in the packages list too. So be aware of this update command.