drush: install specific version

druplicon.small_… don’t know what drupal and drush are? Then this post is probably not for you…

Let’s face it – drush is a bitch to install. But we want it. So we have to. And install it we will!

Even though there appears to be extensive info on the topic on drush’s website, installing it may still be a daunting task.

Particularly – if you don’t run the latest version of php.

Why? Because the “extensive” installation instructions mostly deal with the default installation method which installs the latest version of drush.
…Which means – you’re using drupal 8 (but not all of us do!)…
…Which means – you have the latest php version installed (not all of us do!)
…Which means – you’re using the latest “composer” manager (again… you may not even have composer installed on your system).

SO… What are the ‘Les Miserables’ of us (who for one reason or another do not have the luxury of upgrading their setup to the latest and greatest drupal/php/composer!) to do?

Well… to install drush the standard way you need composer (https://getcomposer.org/doc/00-intro.md). And composer needs php version 5.3.2 or higher to run. So if your php is lower than that and you can not upgrade it then you’re even more screwed.

Your option (since you can not use composer to install drush) is to go to the drush git repository on github (https://github.com/drush-ops/drush) and find a version which is old enough to work with your php/environment.

Since drush versions (which are reflected in the git repo branch names) mimic drupal versions it should not be too hard to find a suitable drush version, knowing that drupal’s php dependencies are as follows:

  • drupal 6 – PHP 5.2.5 or higher
  • drupal 7 – PHP 5.2.5 or higher (>=5.4 recommended)
  • drupal 8 – PHP 5.5.9 or higher

For the rest of us, whose setup is not THAT hopelessly outdated… 🙂  let’s continue with installing composer:

– – – Install composer – – –

1. Get the composer-setup.php script using the php command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

If you feel security-freakish then go to the composer download page to verify the SHA code to make sure your downloaded file is correct.

The composer-setup.php file is what will actually install composer.

2. Choose a good location for composer (preferably within your PATH, for easy invocation).

In my case, since I have a ~/bin dir which is in my PATH, I installed composer there.

3. Install composer
From within your chosen directory run
php composer-setup.php

Alternatively, to install a specific composer version you could run, e.g.
php composer-setup.php --version=1.0.1

The list of composer versions is available here: https://getcomposer.org/download and also there are direct download links for the specific composer versions (in case the composer-setup.php script above does not work).

4. You now should have a composer.phar file in your directory of choice. Use it to install drush. drush could be installed per-project (i.e. per drupal web-site) or globally for the user.

composer require drush/drush:7.x – get the latest 7.x version
…or…
composer require drush/drush:7.1.0 – to get version 7.1.0 (look up the drush versions in the drush git repo: https://github.com/drush-ops/drush[.git])

You should now have a vendor dir structure under your chosen directory and in it, in vendor/bin/drush will be your drush script.

Now, that’s great and all, but you’ll probably say “hey, but this way the drush command is not in your PATH!?”

You’re right! What I did to fix this, was to create a drush directory in my ~/bin dir and inside it add a drush7 dir where to install drush v7. I then symlinked the drush php file from the ~/bin dir (becasue it is in my PATH) and this way I have drush7 available on the command line 🙂

$ mkdir drush
$ mkdir drush/drush7
$ mv vendor drush/drush7
$ ln -s drush7 drush/drush7/vendor/bin/drush

Similarly you can install and create links for a drush6 and drush8 (if you need these versions) and thus have any version of drush available on the command line.

Now… the drush installer pages say that there is a way to install drush globally (using the ‘global’ command with the require drush command above… but I could not get that working for the life of me and I don’t recommend going that route. The above works and is relatively easy to understand and perform .. oh, and did I say it WORKS 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *