diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 34bfcb0..7e1e726 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1594,33 +1594,14 @@ function install_profile_modules(&$install_state) {
   $files = system_rebuild_module_data();
   \Drupal::state()->delete('install_profile_modules');
 
-  // Always install required modules first. Respect the dependencies between
-  // the modules.
-  $required = array();
-  $non_required = array();
-
-  // Add modules that other modules depend on.
-  foreach ($modules as $module) {
-    if ($files[$module]->requires) {
-      $modules = array_merge($modules, array_keys($files[$module]->requires));
-    }
+  $install = array();
+  foreach($modules as $module) {
+    $install[$module] = $files[$module]->info['name'];
   }
-  $modules = array_unique($modules);
-  foreach ($modules as $module) {
-    if (!empty($files[$module]->info['required'])) {
-      $required[$module] = $files[$module]->sort;
-    }
-    else {
-      $non_required[$module] = $files[$module]->sort;
-    }
-  }
-  arsort($required);
-  arsort($non_required);
 
-  $operations = array();
-  foreach ($required + $non_required as $module => $weight) {
-    $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
-  }
+  // Install the given modules.
+  $operations[] = array('_prepare_install_module_batch', array($install));
+
   $batch = array(
     'operations' => $operations,
     'title' => t('Installing @drupal', array('@drupal' => drupal_install_profile_distribution_name())),
@@ -1879,17 +1860,6 @@ function install_finished(&$install_state) {
 }
 
 /**
- * Implements callback_batch_operation().
- *
- * Performs batch installation of modules.
- */
-function _install_module_batch($module, $module_name, &$context) {
-  \Drupal::service('module_installer')->install(array($module), FALSE);
-  $context['results'][] = $module;
-  $context['message'] = t('Installed %module module.', array('%module' => $module_name));
-}
-
-/**
  * Checks installation requirements and reports any errors.
  *
  * @param string $langcode
diff --git a/core/includes/install.inc b/core/includes/install.inc
index 31d472a..2e05721 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -6,6 +6,8 @@
  */
 
 use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Config\PreExistingConfigException;
+use Drupal\Core\Config\UnmetDependenciesException;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\OpCodeCache;
@@ -1102,3 +1104,144 @@ function db_installer_object($driver) {
     return new $task_class();
   }
 }
+
+/**
+ * Batch callback for batch installation of modules.
+ */
+function _prepare_install_module_batch($modules, &$context) {
+  $files = system_rebuild_module_data();
+
+  $install = array_keys($modules);
+  // Add modules that other modules depend on.
+  foreach (array_keys($modules) as $module) {
+    if ($files[$module]->requires) {
+      $install = array_merge($install, array_keys($files[$module]->requires));
+    }
+  }
+  $install = array_unique($install);
+
+  // Always install required modules first. Respect the dependencies between
+  // the modules.
+  $required = array();
+  $non_required = array();
+  foreach ($install as $module) {
+    if (!empty($files[$module]->info['required'])) {
+      $required[$module] = $files[$module]->sort;
+    }
+    else {
+      $non_required[$module] = $files[$module]->sort;
+    }
+  }
+  arsort($required);
+  arsort($non_required);
+
+  $currently_installed = \Drupal::moduleHandler()->getModuleList();
+
+  // Prepare the batch operations.
+  $operations = array();
+  foreach ($required + $non_required as $module => $weight) {
+    if (!array_key_exists($module, $currently_installed)) {
+      $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
+    }
+  }
+
+  // Prevent starting a batch with no operation.
+  if (count($operations)) {
+    // Set the batch.
+    $batch = array(
+      'operations' => $operations,
+      'title' => t('Installing modules.'),
+      'error_message' => t('The installation has encountered an error.'),
+      'file' => 'core/includes/install.inc',
+    );
+
+    batch_set($batch);
+  }
+}
+
+/**
+ * Batch callback for batch installation of modules.
+ */
+function _install_module_batch($module, $module_name, &$context) {
+  $before = \Drupal::moduleHandler()->getModuleList();
+  // Install and enable the module right away, so that the module will be
+  // loaded by drupal_bootstrap in subsequent batch requests, and other
+  // modules possibly depending on it can safely perform their installation
+  // steps.
+  try{
+    \Drupal::service('module_installer')->install(array($module), FALSE);
+  }
+  catch (PreExistingConfigException $e) {
+    $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
+    drupal_set_message(
+      \Drupal::translation()->formatPlural(
+        count($config_objects),
+        'Unable to install @extension, %config_names already exists in active configuration.',
+        'Unable to install @extension, %config_names already exist in active configuration.',
+        array(
+          '%config_names' => implode(', ', $config_objects),
+          '@extension' => $module_name,
+        )),
+      'error'
+    );
+  }
+  catch (UnmetDependenciesException $e) {
+    drupal_set_message(
+      $e->getTranslatedMessage(\Drupal::translation(), $module_name),
+      'error'
+    );
+    return;
+  }
+
+  $context['results'][] = $module;
+  if ($before != \Drupal::moduleHandler()->getModuleList()) {
+    $context['message'] = t('Installed %module module.', array('%module' => $module_name));
+  }
+  else{
+    $context['message'] = t('An error occurred while trying to install %module module.', array('%module', $module_name));
+  }
+}
+
+/**
+ * Batch callback for batch uninstallation of modules.
+ */
+function _uninstall_module_batch($module, $module_name, &$context) {
+  $before = \Drupal::moduleHandler()->getModuleList();
+
+  \Drupal::service('module_installer')->uninstall(array($module), FALSE);
+
+  $context['results'][] = $module;
+  if ($before != \Drupal::moduleHandler()->getModuleList()) {
+    $context['message'] = t('Uninstalled %module module.', array('%module' => $module_name));
+  }
+  else{
+    $context['message'] = t('An error occurred while trying to uninstall %module module.', array('%module', $module_name));
+  }
+}
+
+/**
+ * Batch finish callback for bath installation of modules.
+ */
+function _install_modules_batch_finished($success, $results, $operations) {
+  if ($success && !count($operations)) {
+
+    drupal_flush_all_caches();
+    drupal_set_message(t('The configuration options have been saved.'));
+  }
+  else if(!$success) {
+    drupal_set_message(t('An error occurred while trying to install the selected modules.'));
+  }
+}
+/**
+ * Batch finish callback for bath uninstallation of modules.
+ */
+function _uninstall_modules_batch_finished($success, $results, $operations) {
+  if ($success && !count($operations)) {
+
+    drupal_flush_all_caches();
+    drupal_set_message(t('The selected modules have been uninstalled.'));
+  }
+  else if(!$success) {
+    drupal_set_message(t('An error occurred while trying to uninstall the selected modules.'));
+  }
+}
diff --git a/core/modules/system/src/Form/ModulesListConfirmForm.php b/core/modules/system/src/Form/ModulesListConfirmForm.php
index 5449b41..167c69e 100644
--- a/core/modules/system/src/Form/ModulesListConfirmForm.php
+++ b/core/modules/system/src/Form/ModulesListConfirmForm.php
@@ -7,8 +7,6 @@
 
 namespace Drupal\system\Form;
 
-use Drupal\Core\Config\PreExistingConfigException;
-use Drupal\Core\Config\UnmetDependenciesException;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Extension\ModuleInstallerInterface;
 use Drupal\Core\Form\ConfirmFormBase;
@@ -150,49 +148,23 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
 
-    // Gets list of modules prior to install process.
-    $before = $this->moduleHandler->getModuleList();
-
     // Install the given modules.
     if (!empty($this->modules['install'])) {
-      // Don't catch the exception that this can throw for missing dependencies:
-      // the form doesn't allow modules with unmet dependencies, so the only way
-      // this can happen is if the filesystem changed between form display and
-      // submit, in which case the user has bigger problems.
-      try {
-        $this->moduleInstaller->install(array_keys($this->modules['install']));
-      }
-      catch (PreExistingConfigException $e) {
-        $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
-        drupal_set_message(
-          $this->formatPlural(
-            count($config_objects),
-            'Unable to install @extension, %config_names already exists in active configuration.',
-            'Unable to install @extension, %config_names already exist in active configuration.',
-            array(
-              '%config_names' => implode(', ', $config_objects),
-              '@extension' => $this->modules['install'][$e->getExtension()]
-            )),
-          'error'
-        );
-        return;
-      }
-      catch (UnmetDependenciesException $e) {
-        drupal_set_message(
-          $e->getTranslatedMessage($this->getStringTranslation(), $this->modules['install'][$e->getExtension()]),
-          'error'
-        );
-        return;
-      }
-    }
-
-    // Gets module list after install process, flushes caches and displays a
-    // message if there are changes.
-    if ($before != $this->moduleHandler->getModuleList()) {
-      drupal_set_message($this->t('The configuration options have been saved.'));
+      $operations[] = array('_prepare_install_module_batch', array($this->modules['install']));
+
+      // Set the batch.
+      $batch = array(
+        'operations' => $operations,
+        'title' => t('Installing modules.'),
+        'error_message' => t('The installation has encountered an error.'),
+        'finished' => '_install_modules_batch_finished',
+        'file' => 'core/includes/install.inc',
+      );
+
+      // Redirect the user after install.
+      $form_state->setRedirectUrl($this->getCancelUrl());
+      batch_set($batch);
     }
-
-    $form_state->setRedirectUrl($this->getCancelUrl());
   }
 
 }
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 73b32ec..9d58f05 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -9,8 +9,6 @@
 
 use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Component\Utility\Unicode;
-use Drupal\Core\Config\PreExistingConfigException;
-use Drupal\Core\Config\UnmetDependenciesException;
 use Drupal\Core\Controller\TitleResolverInterface;
 use Drupal\Core\Access\AccessManagerInterface;
 use Drupal\Core\Extension\Extension;
@@ -515,42 +513,20 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       return;
     }
 
-    // Gets list of modules prior to install process.
-    $before = $this->moduleHandler->getModuleList();
-
     // There seem to be no dependencies that would need approval.
     if (!empty($modules['install'])) {
-      try {
-        $this->moduleInstaller->install(array_keys($modules['install']));
-      }
-      catch (PreExistingConfigException $e) {
-        $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
-        drupal_set_message(
-          $this->formatPlural(
-            count($config_objects),
-            'Unable to install @extension, %config_names already exists in active configuration.',
-            'Unable to install @extension, %config_names already exist in active configuration.',
-            array(
-              '%config_names' => implode(', ', $config_objects),
-              '@extension' => $modules['install'][$e->getExtension()]
-            )),
-          'error'
-        );
-        return;
-      }
-      catch (UnmetDependenciesException $e) {
-        drupal_set_message(
-          $e->getTranslatedMessage($this->getStringTranslation(), $modules['install'][$e->getExtension()]),
-          'error'
-        );
-        return;
-      }
-    }
+      $operations[] = array('_prepare_install_module_batch', array($modules['install']));
+
+      // Set the batch.
+      $batch = array(
+        'operations' => $operations,
+        'title' => t('Installing modules.'),
+        'error_message' => t('The installation has encountered an error.'),
+        'finished' => '_install_modules_batch_finished',
+        'file' => 'core/includes/install.inc',
+      );
 
-    // Gets module list after install process, flushes caches and displays a
-    // message if there are changes.
-    if ($before != $this->moduleHandler->getModuleList()) {
-      drupal_set_message(t('The configuration options have been saved.'));
+      batch_set($batch);
     }
   }
 
diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php
index 0208e7c..09e6edf 100644
--- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php
+++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php
@@ -162,11 +162,26 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
 
-    // Uninstall the modules.
-    $this->moduleInstaller->uninstall($this->modules);
-
-    drupal_set_message($this->t('The selected modules have been uninstalled.'));
-    $form_state->setRedirectUrl($this->getCancelUrl());
+    // Prepare the batch operations.
+    $operations = array();
+    foreach ($this->modules as $module) {
+      $operations[] = array('_uninstall_module_batch', array($module, \Drupal::service('module_handler')->getName($module)));
+    }
+    // Prevent starting a batch with no operation.
+    if (count($operations)) {
+      // Set the batch.
+      $batch = array(
+        'operations' => $operations,
+        'title' => t('Uninstalling modules.'),
+        'error_message' => t('The installation has encountered an error.'),
+        'finished' => '_uninstall_modules_batch_finished',
+        'file' => 'core/includes/install.inc',
+      );
+
+      // Redirect the user after removal.
+      $form_state->setRedirectUrl($this->getCancelUrl());
+      batch_set($batch);
+    }
   }
 
 }
