Using multiple versions of drush

updated: April 8th, 2016
updated: April 29th, 2016
updated: March 25th, 2017

Here's how I switch Drush versions using Bash aliases, Composer, and Git. Much of this was taken from https://www.lullabot.com/articles/switching-drush-versions.

Install composer globally

Taken from https://getcomposer.org/doc/00-intro.md#globally

In the terminal:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

If the above fails due to permissions, run the mv line again with sudo.

Add the following line to the top of your ~/.bash_profile (you might need to create this file if it doesn't exist):

export PATH="$HOME/.composer/vendor/bin:$PATH"

Install 4 different versions of Drush with Composer and Drush 5 with git

I have a directory on my computer for all things related to Drupal in my home directory: "~/drupal". In this directory, I have 4 folders, one folder for each version of Drush that I want. I have installed each version of Drush with Composer, except for version 5, which is not supported by Composer. Here's the commands I used:

mkdir ~/drupal/drush9
cd ~/drupal/drush9
composer require drush/drush:9.x@dev
mkdir ~/drupal/drush8
cd ~/drupal/drush8
composer require drush/drush:8.x
mkdir ~/drupal/drush7
cd ~/drupal/drush7
composer require drush/drush:"7.*"
mkdir ~/drupal/drush6
cd ~/drupal/drush6
composer require drush/drush:"6.*"
cd ~/drupal
git clone git@github.com:drush-ops/drush.git drush5
cd ~/drupal/drush5
git checkout 5.x

Make some handy bash aliases for switching versions

In my ~/.bash_profile, I have the following helpful aliases:

alias drush5='~/drupal/drush5/drush'
alias drushup5='git -C ~/drupal/drush5 pull'
alias drushuse5='alias drush="~/drupal/drush5/drush"'
alias drush6='~/drupal/drush6/vendor/bin/drush'
alias drushup6='PREVIOUSDIRECTORY=`pwd` && cd ~/drupal/drush6 && composer update && cd $PREVIOUSDIRECTORY'
alias drushuse6='alias drush="~/drupal/drush6/vendor/bin/drush"'
alias drush7='~/drupal/drush7/vendor/bin/drush'
alias drushup7='PREVIOUSDIRECTORY=`pwd` && cd ~/drupal/drush7 && composer update && cd $PREVIOUSDIRECTORY'
alias drushuse7='alias drush="~/drupal/drush7/vendor/bin/drush"'
alias drush8='~/drupal/drush8/vendor/bin/drush'
alias drushup8='PREVIOUSDIRECTORY=`pwd` && cd ~/drupal/drush8 && composer update && cd $PREVIOUSDIRECTORY'
alias drushuse8='alias drush="~/drupal/drush8/vendor/bin/drush"'
alias drush9='~/drupal/drush9/vendor/bin/drush'
alias drushup9='PREVIOUSDIRECTORY=`pwd` && cd ~/drupal/drush9 && composer update && cd $PREVIOUSDIRECTORY'
alias drushuse9='alias drush="~/drupal/drush9/vendor/bin/drush"'
# Uses v8 for default
alias drush='drush8'
alias drushup='drushup8'

These aliases make it so Drush 7 is used by default. There are aliases to switch the current drush version, and to update specific versions.

Internal References

External References

Article Type

General