Using below example we can check if module is installed or not : <?php if (\Drupal::service('module_handler')->moduleExists('comment')) { echo 'Module Installed'; } else { echo 'Module not installed'; }?> Reference: How can I check if a module is enabled? Tags: Drupal 8