Drupal - Having multiple Drush instances for different core versions

Ideal way would be to use Composer to set up your projects. I'd recommend Composer templates for Drupal projects. Then add Drush to your project: composer require drush/drush.

Now install Drush Launcher on your machine, globally. Drush Launcher provides a drush command that always finds and uses the locally installed Drush from the /vendor folder.

$ cd MYDRUPAL
$ drush --version
Drush Launcher Version: 0.6.0
Drush Commandline Tool 9.3.0

But probably you can not simply rebuild your projects. Then you may want to install two different global Drush versions. See https://github.com/drush-ops/drush/releases for all available versions.

drush8

$ sudo git clone https://github.com/drush-ops/drush.git /usr/local/src/drush8

$ cd /usr/local/src/drush8

# Check the latest Drush 8 version at https://github.com/drush-ops/drush/releases
$ sudo git checkout 8.4.6

# Linux:
$ sudo ln -s /usr/local/src/drush8/drush /usr/bin/drush8

# Mac:
$ sudo ln -s /usr/local/src/drush8/drush /usr/local/bin/drush8

$ sudo composer install

$ drush8 --version
Drush Version   :  8.4.6

drush9

$ sudo git clone https://github.com/drush-ops/drush.git /usr/local/src/drush9

$ cd /usr/local/src/drush9

# Check the latest Drush 9 version at https://github.com/drush-ops/drush/releases
$ sudo git checkout 9.3.0

# Linux:
$ sudo ln -s /usr/local/src/drush9/drush /usr/bin/drush9

# Mac:
$ sudo ln -s /usr/local/src/drush9/drush /usr/local/bin/drush9

$ sudo composer install

$ drush9 --version
Drush Version   :  9.3.0

Source: Installing & Using Drupal Drush on Debian 7 (Bookmark this!)


I do a slightly different method than @leymannx outlined.

I have Drush 8 installed globally. In my case, I have a git clone and I periodically fetch and checkout one of the 8.x.y tags. This is on my bash $PATH. This is what I use to manage my Drupal 7 sites.

All of my Drupal 8 sites use drupal-composer/drupal-project, and include a dependency on drush/drush. I also put

"config": {
    "bin-dir": "bin/"
},

in my composer.json. Then I use direnv to set up a path for the root directory in drupal project. My .envrc will contain a line like

PATH_add /var/www/prod/bin

This prepends $PATH with this directory, so this version of drush will be picked up for that project. This ensures that drush is pulling the same dependencies as that particular drupal install.

Tags:

Drush