You are here

Installing Drush 9 using Composer

I've recently come across this problem a few times while talking to friends and collegues. It seems people are still using Homebrew or other strange methods to try and get Drush installed locally. This is especially frustrating for people looking to get started with Drupal 8 or 9 development as it requires the latest version of Drush. Using Composer is far and away the easiest method to install Drush.

The best way to use Drush 9 is to include it in your project.

First install Composer if you don't have it already. Follow the latest instructions from the official source, getcomposer.org and then return here.

Now that you have Composer, you can include drush in your project.

$ composer require drush/drush:dev-master

Okay now what? How does one use this drush? There are two ways....

Call it directly via the vendor directory

$ vendor/bin/drush status

Or (even better) install the Drush Launcher so that it will auto-discover whatever drush is in your working project folder.

Follow instructions here: Install Drush Launcher and then you can call drush whenever you have it inside the project.

Still, I like the feel of having a "global" drush, so the secret there is to set a system variable in your .bashrc or (my favorite) .zshrc

export DRUSH_LAUNCHER_FALLBACK=/Applications/DevDesktop/tools/drush

Once that is set you can reload your configuration and you should once again be able to call drush from any directory. In the example, I'm using the Drush provided by Dev Desktop as my fallback drush.

This is kind of nice, because I have have Drush 9 on the project level, but also use older Drush 8 aliases with my "global" drush without actually installing it globally.

One should also be able to install Drush globally on their machine.

composer global require drush/drush:dev-master

...but YMMV there.

Again, I recommend the drush launcher.

Some other things you can do with drush and composer...

Keep Drush (and anything else you have installed with Composer) up to date.

$ composer update

Roll back to a release version of Drush 8 if you need to. There are some changes from Drush 8 to Drush 9 and you may find gaps depending on the modules you're using.

$ composer require drush/drush:8.*

That's it!

No really, we're done now.

You can now go back to doing whatever it is you were doing before you realized you needed to install Drush. :)

Submitted by diana on Thu, 05/29/2014 - 22:59