How to Remove Unused Modules in Drupal 8

How to Remove Unused Modules in Drupal 8

One of the important aspects of keeping your Drupal 8 site up-to-date, secure and performing well is to remove unused modules.

There are a number of reasons why you would want to do this:

  • Security – Every module should be kept up-to-date.  If you’re not using a particular feature, you’re just giving yourself more work to do.
  • Performance – Drupal is an event-based CMS so at every point in the page-build process, Drupal is checking to see if any module on your site wants to do something.  All of this adds up!
  • Site clutter – The “Extend” menu is long enough!  Not to mention any configuration menu items that a module might add.
  • Fluff – Some modules just don’t belong – Some development modules such as Devel should never be on a production server.  It’s always best to remove those completely.

Step 1:  Uninstall

When you install a module on your site, depending on the module, a number of things happen.  Obviously the code is added to the /modules folder.  However, if that module stores data in the database, then tables are created and sample data may be installed.  It’s important to uninstall a module before you remove the code so the module’s uninstall configuration file can perform it’s tasks.

It’s also worthy to note that if you simply delete the code without uninstalling, you might encounter a huge performance regression which stems from Drupal recursively searching through the site for the “missing” module on every page load.

Caution:  When you uninstall a module that does write data to the database, all your data will be deleted.

uninstall module - How to Remove Unused Modules in Drupal 8

To uninstall a module:

  1. Log into your Drupal site and click on Extend -> Uninstall
  2. Find the module you wish to uninstall and put a checkmark in the box.
  3. Scroll down to the bottom of the page and click “Uninstall”.

If a module has dependencies, you’ll need to uninstall the module that requires something else first, then the main module second.  For example, Admin Toolbar can not be uninstalled until Admin Toolbar Extras is uninstalled.

uninstall module 2


Step 2:  Remove the module code from the codebase

As you may know, uninstalling a module in Drupal doesn’t actually remove the code from the codebase.  The code stays in the /modules folder, ready to be installed again.  It’s always safest to completely removed the code from your codebase.

If you do not have access to the codebase, you will need to ask your IT department or web host to do that for you.  If your website is hosted on something like Acquia Cloud or Pantheon, those tools are built-in.  If your site is hosted on a popular hosting service such as Hostgator, Hostmonster or Bluehost, you can do that via CPanel.  If your site is hosted on a service such as Digital Ocean, you’ll need SSH access to delete the files.  It’s beyond the scope of this tutorial to dive into every service, but suffice it to say, the files should be deleted.

Once you gain access to the codebase, you’ll look for the modules folder.  Your module will be listed via the machine name.  Just delete the entire folder.  In the illustration below, to delete the Asset Injector module, you would delete the asset_injector folder.

uinstall module 3


One Final Thought

While it might be tempting to uninstall Core modules that you’re not using, it really won’t help. The modules you remove will be reinstalled on the next Drupal update regardless.

Author

  • Rod Martin

    Rod holds two masters degrees and has been training people how to do "things" for over 25 years. Originally from Australia, he grew up in Canada and now resides just outside Cincinnati, Ohio. He has worked in both the non-profit and for-profit worlds, in small companies and large corporations. His extensive open source experience includes WordPress, Joomla and Drupal and he really knows how to help you get the most out of the system you chose. Rod plays ice hockey a couple of times a week and rides his Goldwing motorcycle pretty much everywhere he can.

0 0 votes
Article Rating
Subscribe
Notify of
9 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Sam
Sam
4 years ago

[quote]While it might be tempting to uninstall Core modules that you’re not using, it really won’t help. The modules you remove will be reinstalled on the next Drupal update regardless.[/quote]

Henrik Strindberg
Henrik Strindberg
4 years ago

Thank you for this tutoria! I was just thinking that after uninstalling: if composer is used it’s best to remove the files using the composer remove  command rather than erasing them manually. 
Thanks!

Heinz
Heinz
4 years ago

Hello,
I read in a video tutorial that ALL the modules listed under Admin->Extend->Uninstall may be uninstalled in principle. That is, provided they are not prereqs for some other items. I also understand that it doesn’t make sense to uninstall core modules for obivous reasons. Still, just to make sure again: ALL the modules listed? And – what happens to the config data? Are they deleted automatically when deleting modules or do I additionally have to delete those separately? 
Does composr remove get rid of everything (module code, config, db-data)?
Thanks for your hints – and keep healthy….

John James O'Brien
John James O'Brien
3 years ago

What happens to a Drupal site if a module is simply disabled (deleted/renamed) within CPanel? I find myself locked out as Admin because the Recaptcha module is incorrectly rejecting logins.

– thinking of updating with the latest security update and simply overwriting the modules folder… or just deleting within CPanel… but will that break the site?!

Thx for any advice

Angela
Angela
2 years ago

Thanks so much for your help! This was really useful for someone just getting into Drupal. Bless you <3 

mikall
2 years ago
Reply to  Angela

That’s awesome!! So glad we could help.

9
0
Would love your thoughts, please comment.x
()
x