How do I programmatically install a module?
Use "module_installer" service.

$installer = \Drupal::service('module_installer');
// Or from the container.
$installer = $container-&gt;get('module_installer');

// Install single module.
$installer-&gt;install(['module_name']);
// Install multiple modules.
$installer-&gt;install(['module_name_1','module_name_2']);


Also for uninstallation of the module use the next example:

$installer-&gt;uninstall(['module_name']);