How to uninstall modules in Magento 2?

Installing module in Magento 2 is far easier than uninstalling Magento 2 module(s) so today we are going to cover how to uninstall Magento 2 modules from your webstore without leaving any trace of that module on your filesystem and database 🙂

Here is the step by step guide to uninstall any third party module from Magento 2 manually.

Step 1: Remove the module Vendor_% from appetcconfig.php

Step 2: Drop module tables or columns from database, please check appcodeVendorModuleSetup folder for more information

Step 3: Remove the folder appcodevendor/%

Step 4: Remove module configuration settings from core_config_data table by running the following query

DELETE FROM core_config_data WHERE path LIKE 'vendor%';

Step 5: Remove module from setup_module table by running the following query

DELETE FROM setup_module WHERE module LIKE 'vendor_%';

Step 6: Run the following command by logging onto your SSH server

php bin/magento setup:upgrade

But if you have installed the module via composer then you can run the following list of commands by SSHing on the box to uninstall third party module

php bin/magento module:uninstall -r {{module_name}}

for example

php bin/magento module:uninstall -r Scommerce_GoogleTagManagerPro

-r flag removes module data

Run the following command once module has been successfully uninstalled.

composer remove {{name of the package}}

for example

composer remove scommerce/googletagmanagerpro

Also run the following commands to clean up db and code -:

php bin/magento setup:upgrade
php bin/magento setup:di:compile

Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.