If you have ever installed a new premium theme or attempted a custom sub-theme only to have your site return a white screen of death or an 'unknown error' message, you know how stressful it can be. When the Drupal administrative interface is inaccessible, you cannot simply navigate to the Appearance settings to revert your changes. This is where Drush, the command-line shell for Drupal, becomes an essential tool in your developer toolkit. Knowing how to change the Drupal default theme with Drush is a critical skill for troubleshooting and rapid site management.

In this guide, we will explore the transition from legacy Drush commands to modern configuration management, provide the exact syntax needed to restore your site, and discuss common pitfalls like configuration overrides in your settings file.

Why Your Old Drush Commands Are Failing

If you are coming from a Drupal 7 background, your first instinct might be to use the variable-set (or vset) command. In older versions of Drupal, the default theme was stored as a simple variable in the database. However, since the release of Drupal 8 and continuing through Drupal 9 and 10, the architecture has shifted entirely to the Configuration Management System.

When you attempt to run a command like:

drush vset bartik

You will likely encounter an error stating that the command requires Drupal core version 6 or 7. This is because modern Drupal does not use the {variables} table for these settings. Instead, the theme configuration is stored in a YAML-based configuration object named system.theme. To interact with this, you must use the configuration API through Drush.

The Modern Way: Using Drush config-set

To change the default theme in modern Drupal versions (8, 9, or 10), you must target the specific configuration key that defines the active theme. The command follows a standard pattern: drush config-set [config_name] [key] [value].

To set your theme back to a stable core theme like Olivero (the modern successor to Bartik) or Bartik (if using an older D8/9 site), use the following command:

drush config-set system.theme default olivero

Step-by-Step Breakdown

  1. config-set: This tells Drush you want to modify a configuration object.
  2. system.theme: This is the name of the configuration file where theme settings are stored.
  3. default: This is the specific key within that file that dictates which theme the site uses for front-facing pages.
  4. olivero: This is the machine name of the theme you want to enable.

After running this command, Drush will ask for confirmation. Once confirmed, the configuration is updated in the database. However, your site may still appear broken until you perform the next crucial step.

Clearing the Cache and Rebuilding

Drupal heavily caches theme registries, CSS/JS aggregates, and render arrays. Simply changing the configuration value in the database isn't always enough to reflect the change on the frontend, especially if the site crashed due to a PHP error in the previous theme's template files.

You must rebuild the cache using the cache-rebuild command:

drush cr

Running drush cr (or drush rebuild in some environments) ensures that Drupal clears out the old theme's hooks and starts fresh with your newly assigned default theme. If your site was showing a 500 error, this step is often what actually brings the site back online.

Checking for settings.php Overrides

If you run the config-set command and the site still refuses to change themes, you may be dealing with a configuration override. Drupal allows developers to 'lock' certain settings within the settings.php file. This is common in multi-environment setups (Dev/Staging/Prod).

Open your web/sites/default/settings.php file and look for code resembling this:

$config['system.theme']['default'] = 'my_custom_theme';

If this line exists, any changes you make via Drush or the UI will be ignored because the settings.php file takes precedence. To regain control via Drush, you must comment out or remove that line from the PHP file.

Using theme:enable for a Cleaner Workflow

While config-set is the most direct way to manipulate the underlying data, modern Drush versions provide a more semantic command for managing themes. If the theme you want to switch to isn't currently installed, you should use the theme:enable command first:

drush theme:enable olivero
drush config-set system.theme default olivero

In recent versions of Drush, you can even use the theme:install command which can sometimes handle setting the default theme in a single logical flow, though config-set remains the 'silver bullet' for fixing a crashed site.

Common Mistakes to Avoid

  • Typoing the Machine Name: Ensure you are using the machine name of the theme (e.g., claro instead of Claro). You can find the machine name by looking at the .info.yml file name in the theme folder.
  • Forgetting the Admin Theme: If your site works on the front end but the backend is broken, you may need to change the admin theme as well. Use drush config-set system.theme admin claro to fix the administrative interface.
  • Not Installing the Theme First: You cannot set a theme as default if the system doesn't know it exists. Always ensure the theme is in the /themes directory and is enabled.

Frequently Asked Questions

How do I see a list of available themes via Drush?

You can run drush theme:status (or drush pm-list --type=theme) to see a list of all installed and uninstalled themes available in your codebase. This helps you identify the exact machine name needed for the config-set command.

Can I change the admin theme using Drush too?

Yes! Use the command drush config-set system.theme admin [theme_machine_name]. This is particularly helpful if an experimental admin theme is preventing you from accessing the configuration pages.

Why does Drush say 'command not found'?

This usually means Drush is not installed globally or you are not running it from within the Drupal root directory. If you are using Composer, try prefixing your command with vendor/bin/drush.

Wrapping Up

Mastering the Drush command line is the best way to ensure you can recover a Drupal site from a faulty theme installation. By using drush config-set system.theme default [theme_name] followed by a quick drush cr, you can bypass the graphical interface entirely and resolve site-wide crashes in seconds.

Remember to always verify your settings.php for overrides and keep a stable core theme like Olivero or Claro available as a fallback. With these tools in hand, you can experiment with new Drupal themes with the confidence that you can always get back to a working state.