Uninstall Modules in Magento 2

We are going to discuss here how to uninstall or completely removed the Magento 2 extension using the command line. Please note that this uninstall command only works if you have installed the module by composer command and the module entry is there in the composer.json file of the docroot. If the module is not installed by the composer and you used a zip file to install the module then you have to remove the module files from app/code/YOUR_MODULE instead of following these steps.

How to Uninstall Module using Composer in Magento 2

bin/magento module:uninstall Dhairvi_Demo

You can also pass several parameters with uninstalling command. Below is the format and detailed description of all possible parameters.

bin/magento module:uninstall [--backup-code] [--backup-media] [--backup-db] [-r|--remove-data] [-c|--clear-static-content] {Module_Name}

{Module_Name}, is the name of your Magento 2 extension.
–backup-code: If you pass this parameter then it back up the Magento file system (excluding var and pub/static directories).
–backup-media: This parameter back up the pub/media directory.
–backup-db: This parameter back up the Magento 2 database.
–remove-data: This parameter removes the database schema and data defined in the module’s Uninstall classes.
–clear-static-content: This parameter cleans generated static view files.

Note: If you never want to use this module in future then only use uninstall command. Instead, disable the module using the below command.

bin/magento module:disable {module_name}