Install and uninstall modules programmatically in drupal 8

To install a module.

\Drupal::service('module_installer')->install(['module_name']);

To uninstall 

\Drupal::service('module_installer')->uninstall(['module_name']);