Installing and running Drush

Objectives
  • Install Drush per-site with Composer
  • Run drush
  • Update Drush with Composer
Prerequisites
  • Basic command-line use
  • Basic Composer use

Installing Drush

As of Drupal 8, you must use Composer to install Drupal core, modules, themes, and other dependencies and development tools such as Drush.

Note

If you are using local development environments based on virtual machines or containers (such as DDEV or Lando), be sure to install Drush inside your development environment, not on your host machine.

To install Drush, run the following command inside your local environment directory or inside your Drupal root directory:

composer require drush/drush

This will make the drush command available in your project's vendor/bin directory:

vendor
├── ...
├── bin
│   ├── ...
│   ├── drush

Note

Your vendor directory should be located directly inside your project root (not inside your Drupal root directory). This is a recommended good practice, and it's the default for DDEV environments. Going forward we assume this is the case for your environment as well.

Running drush

If you use DDEV, the drush command is available from every directory or subdirectory in your local environment directory.

If the command is not available, you need to either provide the path to the drush command:

sarah@demo-web: /var/www/html/web/modules/custom$ ../../../vendor/bin/drush

or add the relative ./vendor/bin path to your shell's $PATH variable and only run drush from your project's root directory:

sarah@demo-web: /var/www/html$ drush

See also:

Troubleshooting

  • Ensure the drush command is present in your environment's vendor/bin directory.
  • If you're using the full path to the drush command in vendor/bin, ensure it is correct.
  • If you're not using DDEV, ensure ./vendor/bin is added to your shell's $PATH variable (and that you restarted your shell session). 

Updating Drush

You update Drush the same way you update other Composer dependencies:

composer update drush/drush

Summary

  • Drush must be installed using Composer.
  • Install Drush with composer require drush/drush.
  • Update Drush with composer update drush/drush.
  • The drush command is placed in your environment's vendor/bin directory.
  • You may need to add ./vendor/bin to your shell's $PATH variable.