Multiple Drush versions on one system


To work on both drupal7 and drupal8 projects, we need drush6 and drush8 on our dev environment (in my case this is ubuntu 14.04 server). I'm doing this on a clean server with a lamp stack and git installed, no drush is present yet. This can also be used to install drush8 on a server with an existing drush version, in that case only use the commands for composer and drush8.

What this will do is use 'drush6' as the default drush command for 6 and 'drush8' as the default for 8. We will be using the terminal to install everything.

Install composer:

> curl -sS | php

> sudo mv composer.phar /usr/local/bin/composer

> sudo ln -s /usr/local/bin/composer /usr/bin/composer 

Install both Drush versions:

For drush 6 (drush command in terminal will be 'drush6'):

> sudo git clone /usr/local/src/drush6

> cd /usr/local/src/drush6

> sudo chown -R [youruser]:[yourgroup] /usr/local/src/drush6

> sudo git checkout 6.6.0

> sudo git checkout -b 6.6.0

> sudo ln -s /usr/local/src/drush6/drush /usr/bin/drush6

> sudo composer install


Now I also want to use the command 'drush' as the default command for drush6 because some of our scripts use the default 'drush' command, which is not available when using this setup.

That's why we'll add a new symlink, do keep in mind that if you ever want to use the default 'drush' command for drush8, you'll have to change this symlink.

> sudo ln -s /usr/local/src/drush6/drush /usr/bin/drush


For drush 8 (drush command in terminal will be 'drush8'):

> sudo git clone /usr/local/src/drush8

> cd /usr/local/src/drush8

> sudo chown -R [youruser]:[yourgroup] /usr/local/src/drush8

> sudo git checkout master

> sudo ln -s /usr/local/src/drush8/drush /usr/bin/drush8

> sudo composer install

Expose the path

In order to be able to use drush we will need to make sure that the drush commands are in our path variable, we do this in the .bashrc (.bash_profile for Mac OS users) file in our home directory. We will also add aliases to our drush commands in the same .bashrc (.bash_profile for Mac) file to be able to use a shorter command (the aliases are optional). In your .bashrc (.bash_profile for Mac) file add the following:

To open our .bashrc file:

> nano ~/.bashrc

Now enter this at the bottom of the file and save afterwards:

> export PATH="/usr/bin:$PATH"

> alias d6='/usr/bin/drush6'

> alias d8='/usr/bin/drush8'

Test the Drush commands:

Now exit and reopen your terminal to make sure the .bashrc (.bash_profile for Mac) changes are picked up and type these commands in terminal to see if everything works as expected:

> drush --version 

Should output: Drush Version : 6.6.0


> drush6 --version 

Should output: Drush Version : 6.6.0


> drush8 --version 

Should output: Drush Version : 8.0-dev


> d6 --version 

Should output: Drush Version : 6.6.0


> d8 --version 

Should output: Drush Version : 8.0-dev


Now you should have 2 working versions of drush, both installed separately. You can use this method to add more versions if you ever need to. This may seem like a complex method, but the advantage of this method is that you don't have to explicitly change drush versions every time you work on a different drupal version. Another advantage is that all drush versions are separated on your system and you can upgrade or downgrade a specific version of drush whenever you like, without affecting other drush versions.

I hope this helped you, happy coding!

Recommended articles
Hiring digital talent to help businesses transition towards a new economy
New: Gitlab integration into Dropsolid Experience Cloud
JAMStack, Cloud IDE’s & Privacy - tech that will shape 2021
3 reasons to invest in your digital customer experience
Dropsolid at Drupalcon Global 2020

Want to learn how Dropsolid Platform can help your organization increase its customer lifetime value?

Request a free trial now and get started with the Dropsolid Experience Cloud under the guidance of our CTO Nick Veenhof and our customer support teams.

Nick Veenhof CTO