How to Remove/Uninstall Magento 2 Extension?
Removing an extension in Magento 2 is more complex than in Magento 1 to ensure system stability, especially in cases with dependencies. There are two main methods to remove an extension in Magento 2: Manual Removal and Removal using Composer (Simple & Complex). Here’s how you can do it:
Manual Removal
If your store does not use Composer, you can remove the extension manually. Follow these steps:
- Login to your domain via SSH/CLI and navigate to the root of your store.
- Check the status of enabled modules: bashCode kopiëren
bin/magento module:status
Identify the internal name of the module you wish to remove, for example,uninstallext_Demo
. - Disable the module:bashCode kopiëren
bin/magento module:disable <Internal Module Name>
For example:bashCode kopiërenbin/magento module:disable uninstallext_Demo
- Upgrade setup to remove the module from all store activities: bashCode kopiëren
bin/magento setup:upgrade
- Remove the module directory:bashCode kopiëren
rm -rf <Module Directory>
- Clean the cache:bashCode kopiëren
bin/magento cache:clean
- Regenerate static contents:bashCode kopiëren
bin/magento setup:static-content:deploy -f
Note: Manual removal might leave some errors unchecked, so using Composer is recommended for extension removal.
Removing with Composer (Simple)
Using Composer is the safest way to remove a Magento 2 extension. If the extension has no dependencies, use the Simple removal method:
- Login to your domain via SSH/CLI and navigate to the root of your store.
- Check the status of enabled modules: bashCode kopiëren
bin/magento module:status
Identify the internal name of the module you wish to remove, for example,uninstallext_Demo
. - Disable the module:bashCode kopiëren
bin/magento module:disable <Internal Module Name>
For example:bashCode kopiërenbin/magento module:disable uninstallext_Demo
- Upgrade setup to remove the module from all store activities: bashCode kopiëren
bin/magento setup:upgrade
- Locate the module’s composer.json file: For example, it would be located at
/vendor/uninstallext/module-demo/composer.json
. - Remove the extension using Composer: bashCode kopiëren
composer remove <composer name>
For example:bashCode kopiërencomposer remove uninstallext/module-demo
Note: This method is applicable only when the extension has no dependencies.
Removing with Composer (Complex)
If the extension has dependencies, use the Complex removal method:
- Login to your domain via SSH/CLI and navigate to the root of your store.
- Check the status of enabled modules: bashCode kopiëren
bin/magento module:status
Identify the internal name of the module you wish to remove, for example,uninstallext_Demo
. - Uninstall the module:bashCode kopiëren
bin/magento module:uninstall [options] <internal module name>
For example:bashCode kopiërenbin/magento module:uninstall uninstallext_Demo
- Optional backup options:
- Backup database:bashCode kopiëren
bin/magento module:uninstall --backup-db
- Backup media:bashCode kopiëren
bin/magento module:uninstall --backup-media
- Backup code:bashCode kopiëren
bin/magento module:uninstall --backup-code
- Remove all tables created by the module:bashCode kopiëren
bin/magento module:uninstall --remove-data
- Clean static files:bashCode kopiëren
bin/magento module:uninstall --clear-static-content
- Backup database:bashCode kopiëren
- Handle dependencies: If dependencies are found, prepend them to the module name: bashCode kopiëren
bin/magento module:uninstall --backup-db --clear-static-content Magento_SampleData Magento_Demo
- Complete the removal process:bashCode kopiëren
bin/magento module:uninstall
This will automatically put your store in maintenance mode, disable and remove applications, clean the cache, and remove all specified data. Composer will then complete the removal.
We hope this article helps you in the removal process of Magento 2 extensions.