Last updated February 21, 2020

Drush is the command line shell and Unix scripting interface for Drupal. The most common way to install Drush is to install it on a per-project basis using Composer. We'll walk through the steps do to that, as well as how to setup the Drush Launcher tool to make it possible to execute Drush commands without having to specify a full path to the executable.

In this tutorial we'll:

  • Install Drush
  • Install Drush Launcher
  • Verify it worked

By the end of this tutorial you'll have Drush installed.

Goal

Install Drush and verify it's working.

Prerequisites

Install Drush using Composer

This assumes that your Drupal codebase is managed using Composer. The current recommendation is to install Drush on a per-project basis. This allows for having different versions of Drush installed for different projects. This is a best practice because different versions of Drush are compatible with a particular set of Drupal versions.

Run composer require

In most cases it's best to install Drush as a development dependency. From the root directory of your project run the following command:

composer require --dev drush/drush

Once that's completed run the command ./vendor/bin/drush --version to verify it worked.

./vendor/bin/drush --version
# > Drush Commandline Tool 10.2.1

Optionally install Drush launcher

Rather than have to type ./vendor/bin/drush or the relative path to the executable in order to execute Drush commands, install the Drush Launcher. That is a small program which listens on your $PATH and passes control to a project-specific Drush installation in the /vendor directory of the project associated with your current working directory. (The directory you're running drush within is somewhere in your project's directory hierarchy.)

This requires installing a PHP Phar; the following is copied from the documentation at https://github.com/drush-ops/drush-launcher.

OSX:

curl -OL https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar

Linux:

wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar

Make downloaded file executable:

chmod +x drush.phar

Move drush.phar to a location listed in your $PATH, and rename to drush:

sudo mv drush.phar /usr/local/bin/drush

Windows users: create a drush.bat file in the same folder as drush.phar with the following lines. This gets around the problem where Windows does not know that .phar files are associated with php:

@echo off
php "%~dp0\drush.phar" %*

Finally, use drush --version to verify it worked. Note: you no longer need to specify ./vendor/bin/. As long as you're somewhere within the Drupal project's directory structure the Drush Launcher will locate the copy of Drush in ./vendor/bin/drush and call it.

Recap

In this tutorial we learned how to use Composer to install Drush as well as how to use the Drush Launcher tool to make it easier to execute Drush commands without having to provide a full path to the executable.

Further your understanding

  • Run the drush command with no arguments to see a list of available Drush commands.

Additional resources