Once you install Magento 2, usually you require to install Magento 2 extensions to build a fully functional store. As the time and website grow, you realize that some of the extensions are not best-fit or some forfeit their usefulness or their functionality is no longer required or you require reinstallation, it’s time when you want to uninstall and remove a Magento 2 extension.
Moreover, when there are a large number of extensions in Magento 2 store, it affects various factors adversely, although offering its functionality. Such factors are the increase in loading time, conflictions occurring between two extensions, SQL errors due to third-party extensions. Due to these reasons, you may require to uninstall a Magento 2 extension.
Also, you may want to remove a module that offers the same functionality as an already installed extension.
A large number of extensions also results in the complexity of store structure. Isn’t this enough reason to remove the unwanted extensions? Let’s see how the process can be done.
Uninstalling an extension should be a simple task but not always. They leave behind data in a number of places in the database which occupy unnecessary space and affects the store’s performance. Today, I have come up with 2 methods to uninstall and remove a Magento 2 extension.
The extension uninstallation method depends on its installation process.
Method 1: Uninstall and Remove a Magento 2 Extension Manually
Step 1: Connect via SSH to the root of your Magento installation (the folder that has the app folder in it) and go through the list of all extensions including their enable/disable status
php bin/magento module:status
Step 2: Disable the extension by executing the given commands:
php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content
php bin/magento setup:upgrade
Step 3: Remove the extension files
cd app/code/<ExtensionProvider>/
rm -rf <ExtensionName>
Note: Don’t make the mistake to remove the shared extension from a common vendor. You may end up deleting the dependency pack that serves as a base for all their extensions.
Example: Suppose you are using Magento 2 Flat Rate Shipping Extension by Meetanshi and you want to uninstall it and remove all associated files:
php bin/magento module:disable Meetanshi_Flatshipping --clear-static-content
php bin/magento setup:upgrade
cd app/code/Meetanshi/
rm -rf Flatshipping
Method 2: Composer Uninstallation Method
Step 1: Connect via SSH to the root of your Magento installation (the folder that has the app folder in it) and check the list of all modules including their enable/disable status
php bin/magento module:status
Step 2: Disable the module by executing the given commands:
php bin/magento module:disable <ExtensionProvider_ExtensionName> --clear-static-content
php bin/magento setup:upgrade
composer remove VendorName/VendorExtensionRepository
- You can find the exact match for ExtensionProvider and ExtensionName in composer.json file associated with the module.
- Also, you can get VendorName and VendorExtension in composer.json file associated with the extension.or under yourmagentoinstallation/com/vendor/<VendorName>/<VendorExtension>
- If you are asked for composer username and password while the uninstallation process, navigate to var/composer_home/auth.json.
Example: Let’s take the example of the same extension for this method as well. First of all, disable the extension, run the setup upgrade and finally remove the files via composer:
php bin/magento module:disable Meetanshi_Flatshipping --clear-static-content
composer remove meetanshi/m2-meetanshi-flatshipping
php bin/magento setup:upgrade
Note: Along with removing the extension, you would want to remove the extension attribute or product attribute that might be created. If so, remove the extension attribute from the table with this method:
go to phpmyadmin -> search table “eav_attribute”
and remove that extension attribute from the table
I have tried to present the easy ways to uninstall a Magento 2 module.
Also, you can always follow the Magento DevDoc to uninstall modules.