Objectives & prerequisites
- Install Drush per-site with Composer
- Run drush
- Update Drush with Composer
- 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/drushThis will make the drush command available in your project's vendor/bin directory:
vendor
├── ...
├── bin
│ ├── ...
│ ├── drushNote
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/drushor 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$ drushSee also:
- How to add directory path to $PATH variable in Linux (linuxconfig.org)
Troubleshooting
- Ensure the
drushcommand is present in your environment'svendor/bindirectory. - If you're using the full path to the
drushcommand invendor/bin, ensure it is correct. - If you're not using DDEV, ensure
./vendor/binis added to your shell's$PATHvariable (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
drushcommand is placed in your environment'svendor/bindirectory. - You may need to add
./vendor/binto your shell's$PATHvariable.