Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Using Drush for Updates

Introduction to Drush

Drush is a command line shell and scripting interface for Drupal. It enables developers and site administrators to perform various tasks quickly and efficiently without navigating through the Drupal administrative interface. One of the most critical functions is performing updates on your Drupal site.

Installing Drush

Before you can use Drush, you need to have it installed. You can install Drush using Composer, which is the recommended way. Here’s how you can do it:

Open your terminal and run:

composer global require drush/drush

Make sure to add Composer's global bin directory to your PATH so you can run Drush from any location.

Checking Drush Installation

After installation, you can verify if Drush is installed correctly by running the following command:

drush --version

This command will return the version of Drush you have installed, confirming that Drush is set up correctly.

Updating Drupal Core

To update your Drupal core using Drush, follow these steps:

First, you should check for available updates. Run:

drush pm-updatestatus

This will list all available updates for your installed modules and themes. To proceed with the core update, use:

drush up drupal

Drush will handle downloading the latest version of Drupal core and apply the update automatically.

Updating Modules

Updating modules is just as straightforward. You can update all modules by running:

drush pm-update

If you want to update a specific module, you can specify its name:

drush pm-update [module_name]

Replace [module_name] with the actual name of the module you wish to update.

Clearing Cache After Updates

After performing updates, it’s essential to clear the cache to ensure that the changes take effect. You can clear the cache using the following command:

drush cr

This command will clear the cache for your Drupal site.

Rollback Updates

If there’s an issue after an update, you might want to roll back to a previous version of a module. Drush provides commands to revert updates, but you must have the backup of your site or use version control. You can revert using:

drush pm-revert [module_name]

Again, replace [module_name] with the name of the module you want to revert.

Conclusion

Using Drush for updates is a powerful way to manage your Drupal site efficiently. By following the steps outlined in this tutorial, you can easily keep your Drupal core and modules up to date, ensuring that your site runs smoothly and securely.