How to Remove/Uninstall Magento 2 Extension?
In Magento 1, if you wanted to remove the extension, you only have to remove module files and special config XML files at app/etc/modules directory, but Magento 2 has a more complex way to remove the extension.
It ensures system stability in cases of complex uninstall with dependencies.
There are two ways to remove the extension.
- Manual Removal
- Removal using composer ( Simple & Complex)
Let’s see how you can remove or uninstall Magento 2 extension using this methods
Manual Removal
In case your store does not use composer, you can try to remove the extension manually.
Here are the steps to remove Magento 2 extension manually
- Login to your domain via SSH/CLI and go to the root of your store.
- Run this command-
bin/magento module:status.
It will allow you to see a list of enabled modules pick up an internal name of the module you wish to remove.
uninstallext_Demo, for example.
- Run command-
bin/magento module:disable <Internal Module Name>.
In this example, it would be
bin/magento module:disable uninstallext_Demo.
This command will disable the module
- Run command
bin/magento setup:upgrade.
This command will make Magento 2 remove it from all store activities.
- Run command rm -rf <Module Directory>.
- Run this command to clean the cache
bin/magento cache:clean
Then run this command to regenerate static contents
bin/magento setup:static-content:deploy -f
Using this method might leave some unchecked errors, so we recommend to use composer for extension removal.
Removing with Composer (simple)
Using composer to remove Magento 2 extension is the safest way. However there are both simple and complex method to remove Magento 2 extension.
If your extension has no dependencies and connections with other extensions then Simple removal is the best method for you.
Here are the steps to remove Magento 2 extension with Simple removal method.
- Login to your domain via SSH/CLI and go to the root of your store.
- Run this command-
bin/magento module:status.
It will allow you to see a list of enabled modules, pick up an internal name of the module you wish to remove.
uninstallext_Demo for example.
- Run command-
bin/magento module:disable <Internal Module Name>.
In this example it would be
bin/magento module:disable uninstallext_Demo.
This command will disable the module
- Run command
bin/magento setup:upgrade.
This command will make Magento 2 remove it from all store activities.
- Now, go to the root directory of the module you wish to remove. You will find composer.json file.
In this example it would be located at
/vendor/uninstallext/module-demo/composer.json
You will find your module composer name In attribute name.
- Go back to your store´s root and run command
composer remove <composer name>
In our example it would be
composer remove uninstallext/module-demo.
It’s done. Once you run this command, composer will remove all extension files.
But this case is only applicable when the extension doesnt have any dependencies, in case you don’t know much about the dependencies, it is always better to use the complex method to ensure that your store is not affected in any way.
Removing with Composer (complex)
If your module is very involved with your store, especially when the extension has dependencies with other extensions, it is recommended to use the Complex removal approach. Unlike older version of Magento, Magento 2 has made this process automated and it has a special command for it.
Here are the steps to remove Magento 2 extension with Complex removal method.
- Login to your domain via SSH/CLI and go to the root of your store.
- Run this command-
bin/magento module:status.
It will allow you to see a list of enabled modules, pick up an internal name of the module you wish to remove.
uninstallext_Demo for example.
- Run this command
bin/magento module:uninstall [options] <internal module name>
In our case it would be
bin/magento module:uninstall uninstallext_Demo
- Magento can automatically backup your database if you want, just add option –backup-db.Tar-gzipped backup file will be placed to /var/backup directory.
- Magento can automatically backup all store media (/pub/media directory), add option –backup-media. It will be also placed to /var/backup directory.
- Magento can automatically backup store code (it is useful for restoring system in case there is a incorrect removal), add option –backup-code. Your entire store will be backed up except for temporary or generated directories. It will be placed to /var/backup directory.
- Automatically remove all tables, created by module, by adding option –remove-data.
- Automatically clean static files after removal by adding option –clear-static-content.
- For example,
If you want to backup the database and regenerate static contents, full command.
In our case, it would be,
bin/magento module:uninstall --backup-db --clear-static-content uninstallext_Demo
If this command finds any dependencies, it will stop and show them to you.
bin/magento module:uninstall uninstallext_Demo
Cannot uninstall module ‘Magento_Demo’ because the following module(s) depend on it:
uninstallext_SampleData
In this case, just prepend dependencies to your module name. So the command will look like this:
bin/magento module:uninstall --backup-db --clear-static-content Magento_SampleData Magento_Demo
Run Command bin/magento module:uninstall then it will automatically put your store to maintenance mode. It will disable and remove applications clean the cache and all data that you had specified in the options available.
Once done, it will run the composer removal command, and when it gets completed, it will automatically disable the maintenance state.
We hope this article helps you in the removal process.