Installing Drush 8 globally
Drush is an amazing tool for Drupal developers but their installation instructions are a bit difficult to follow. After doing it a few times, I figure I can't be alone in trying to figure this out so here are the instructions I've been following.
I've tested them on Debian and Ubuntu systems.
Installing Drush is a two part process. Step 1: download Drush. Step 2: install it using Composer.
Let's get started. First you need to know which version is compatible with the version of Drupal and PHP you are using. You can find a chart here: http://docs.drush.org/en/master/install/
Currently, Drush 8 works with Drupal 6/7/8 and seems the most stable and full featured. I've heard from front-end people that there may be some issues with Omega compatibility but I don't need those features so I can't verify.
Sometimes that Drush page shows the build status as failing for a particular project but you can ignore that. We're going to download a stable tagged version. The build status refers to the branches (dev versions) which fluctuate.
Go to https://github.com/drush-ops/drush to download the version of Drush that works for you. I'll use the latest stable release of Drush 8 in this example.
You will see the branch dropdown on the left near the top. Click on that and then select the "Tags" tab and click on the latest tag for the version of Drush you want. In my case it was 8.1.3.
Once you have selected the tag, click on the "Clone or Download" button on the right side of the page. Download the .zip file and unzip it into /usr/local/bin as root.
You should end up with a Drush in a directory like this:
/usr/local/bin/drush-8.1.3
And the Drush executable inside that directory like this:
/usr/local/bin/drush-8.1.3/drush
Next, if you don't have composer installed, you'll need to get it and put it in the /usr/local/bin directory to finish the installation:
You can find out if it is installed by typing:
$ which composer
or
$ which composer.phar
If you get a result with a path to composer, skip to where we do "composer.phar install", otherwise (as root or with sudo):
$ cd /usr/local/bin $ curl -sS https://getcomposer.org/installer | php
Make sure it is executable if it isn't already (this used to be an issue but hasn't been in recent installs):
$ chmod u+x composer.phar
Now cd into the drush directory and run composer:
$ cd /usr/local/bin/drush-8.1.3 $ composer.phar install
Drush is now installed.
Note: I like to
$ mv composer.phar composer
But it's not required.
In order to allow all users on the system to use Drush, you can put it in the $PATH by linking it to the /usr/local/bin directory. Remember, subdirectories inside bin are not in $PATH. $ cd /usr/local/bin $ ln -s /usr/local/bin/drush-8.1.3/drush /usr/local/bin/drush
Now if you cd to anywhere in the file system, you should be able to do this:
$ which drush /usr/local/bin/drush
Now you need to cd into the drush directory and run composer install:
$ cd /usr/local/bin/drush-8.1.3 $ composer install
Finally, if you run this...
$ drush init
...Drush will add some Bash aliases to your .bashrc. Source your .bashrc or logout and back in to see the effects. Do that as each user that uses Drush.
E.g. this will cd you to the site's root directory and change your prompt to show the current Git branch and status if a repository is found:
$ cdd @mysite
If you made is this far and want to see some of the power of Drush in action, check out part two of this series: Drush 8: quick passwordless site syncing and other time savers for Drupal developers