very helpful lioness

Running both Drush 8 (for Drupal 7) and Drush 10 (for Drupal 9) at the same time

Mon, 09/14/2020 - 02:49 -- webchick


These days, my life is all migrations, all the time, which means I often need to run Drupal 7 and Drupal 9 sites side-by-side simultaneously to compare the results.

The problem?

Table of Drush compatibility info from https://www.drush.org/install/

The latest version of Drush, Drush 10, only works on Drupal versions 8.4+. To use Drush on Drupal 7 sites, you need an older version, Drush 8. And both of them use the command drush. Tricksy...

There are various Drupal-knowledgeable local development environments, such as Acquia Dev Desktop, Lando, DDEV, and Drupal VM that handle this complexity for you, which is super handy. However, the rest of my team uses a "from scratch" local development environment on Mac OS X, so I needed to figure out how to do this by hand.

I made a Twitter inquiry if there was an existing tutorial on how to do this, and since I couldn't find one, here it is. :) Hopefully this helps others, as well! (Thanks to those who responded, pointing me in the right direction!)

1. Installing Drush 8 for your Drupal 7 sites

https://docs.drush.org/en/8.x/install/ are the installation docs for Drush 8. While the recommended way to install all versions of Drush is to pull it in as a local Composer dependency (we'll go through that route in a sec), almost 0% of Drupal 7 sites are installed with Composer (and mine certainly weren't :P), since Composer was not even a "thing" back then. This means you typically need to install it instead globally, so it's available to all D7 sites on your computer.

To do this:

1. Go to https://github.com/drush-ops/drush/releases and download the latest Drush 8 release's "drush.phar" file (as of this writing, 8.4.1).

2. Test that it's working by attempting to run it with PHP:

$ php PATH_TO_DRUSH/drush.phar --version
Drush Version : 8.4.1

3. Since it's super annoying to type php PATH_TO_DRUSH/drush.phar all the time, make it executable and move it somewhere in your $PATH.

chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush

Now you can execute with just drush [whatever] from within a given Drupal 7 site's docroot. Perfect!

2. Installing Drush 10 for your Drupal 8/9 sites

Well. Perfect except for the not-so-minor detail that despite Drush 8 working surprisingly well for not being supported in Drupal 8.4+, it is nevertheless not supported in Drupal 8.4+. Also, there are newer, useful commands in Drush 10 that are not available in Drush 8, such as drush config:satus.

So! Let's fix this by adding Drush 10 to our Drupal 9 site. https://www.drush.org/install/ has the installation instructions.

The "best practice" way to do this is in Drupal 9, since the code base has already been "Composer-fied" out of the box (thanks, Composer initiative!) is to add Drush in as a dependency:

cd PATH_TO/drupal9
composer require drush/drush

Check to make sure it's working:

drush --version
Drush Commandline Tool 10.3.4

Move back to your Drupal 7 directory and you should see:

drush --version
Drush Version : 8.4.1


3. That's it. Don't do anything else. ;)

I figured I would need Drush Launcher to finish things off, but it appears that Drush 8 has some basic launch-like capabilities in it, because it automatically switches from one to the other seamlessly. Nifty!

And in fact, if you do install Drush launcher, Drush 8 won't work anymore. (Womp, womp.) Which brings us to...


It says "command not found" when I type "drush"
That probably means that the place you moved Drush 8 to is not in your $PATH. Try echo $PATH and move it to somewhere in that list, or add your desired location to $PATH in ~/.bash_profile
It says "mv: rename drush.phar to /usr/local/bin/drush: No such file or directory," but /usr/local/bin exists!
Don't forget to chmod it first.
When I run "drush" from within Drupal 7, it says "The Drush launcher could not find a Drupal site to operate on."
Ah, you skipped the tutorial and installed Drush Launcher. ;) Following those steps will blow away your Drush 8 installation, which also lives at /usr/local/bin/drush. You can either re-do the steps above to use Drush 8, and thus kill your Drush Launcher (Drush 8 seems to have basic Drush Launcher capabilities, which is nice), or you can Composer-ize your Drupal 7 code base and then add Drush 8 as a dependency, just as you did with Drush 10, with:

composer require drush/drush:~8


Submitted by Matthew Tift (not verified) on

Thanks, Angie! This works much better than the craziness I was doing before that required me to have to constantly remember (and often forget) if I should type "drush" or "drush8".

Submitted by Peter Stub (not verified) on

I followed the above steps - and can also do a drush --version from within my d7 root - and I get correct info - but a "drush cr" gives me a "higher bootstrap level to run" message.

Did Google alot - but cant get it to work.

U got any ideas?