How to have multiple Drush versions installed

STEP 1 - Uninstall Drush

I'll assume you have composer and Homebrew installed. 

If you already have Drush running you better uninstall it.
You can do that by running this command if you had previously installed it using Homebrew:

$ brew remove --force drush

STEP 2 - Install de default Drush version you want to run

Find the versions of Drush you want to run here https://packagist.org/packages/drush/drush

I decided to have Drush 7 as default global Drush version. To do so I ran this command:

$composer global require drush/drush:7.x-dev

Run this command instead to install the latest stable version of Drush as default:

$composer global require drush/drush

Then edit your .bashrc ( if using MacOS) .bash_profile (for Linux) by using the following command:

$vim ~/.bashrc 

and add the following line:
export PATH="$HOME/.composer/vendor/bin:$PATH”

If you are using oh-my-zsh bash profile then edit the .zshrc file instead.

$vim ~/.zshrc

Restart your terminal.

Run $drush command to see if it works

STEP 3 - Install another Drush Version 

I will choose Drush 8 as my alternative Drush version for this tutorial.

Create a directory for each Drush version you want to have running.
You can do it anywhere but it will be better to have it in the user directory.

$mkdir ~/drush8

Then cd to that directory and run the following command to install Drush8 inside:

$composer require drush/drush:dev-master

Then edit your .bachrc file or .zshrc again and add the following alias. You should add one alias for every Drush version you have installed:
alias drush8='~/drush8/vendor/bin/drush’

Restart your Terminal.

After that you can call $drush command for the default drush version ( drush7 in my case) and $drush8 command to call Drush 8 Version.

Enjoy!! 

alarez's picture

Posted by alarez

Alain has been involved in the web industry for the past 10 years as a Graphic Designer, FrontEnd Developer, Drupal Developer, Project Planner and Consultant. He is used to work closely with clients turning ideas into achievable tasks and measurable outcome. Given his 6+ years of Drupal experience he stays close to the developers trying to refine working processes and deliver optimal results. "Through all my years as a designer and developer I have come to the conclusion that in order to learn something, you have to do it wrong the first time. Is good to be wrong, so you can learn something from the experience"

Our Drupal Contributions

Take a look at our Drupal Give page, where we are listing some of the contributions that our team have done to the Drupal project.