The configuration management system does not allow modules to provide configuration on an installation that already exists. For example, if a module tries to provide system.site and defines the site's name, it would fail to install. This is because the system module provides this configuration object when you first install Drupal.
Drupal provides hook_install() that modules can implement in their .install file. This hook is executed during the module's installation process. The following code will update the site's title to Drupal 8 Cookbook! on the module's installation:
/**
* Implements hook_install().
*/
function mymodule_install() {
// Set the site name.
\Drupal::configFactory()
->getEditable('system.site')
->set('name', 'Drupal 8 Cookbook!')
->save();
}
Configurable objects are immutable by default when loaded by the default config service. To modify a configuration object, you will need to use the configuration factory to receive a mutable object. The mutable object can have set and save methods that are executed to update the configuration in a configuration object.