Following the official installation guide, we're going to setup global accessible Drush installation. The benefit of using such method is that any user can run the Drush command. Note that I'm currently using Fedora Rawhide (F22) but this should be applicable to all GNU/Linux distros.
First, make sure you've already install the Git version control tool. If not, just install it.
$ sudo yum install git php php-pear $ sudo pear install Console_Table
Next, we'll clone the Drush from the Github repository. Rather than following the convention of installing it in /usr/local directory, I opt for /opt directory to differentiate packages or software installed by distribution and myself. Although the Drush command still depends on PHP binary from the default distribution.
$ sudo git clone https://github.com/drush-ops/drush.git /opt/drush Cloning into '/opt/drush'... remote: Counting objects: 29817, done. remote: Compressing objects: 100% (17/17), done. remote: Total 29817 (delta 6), reused 0 (delta 0), pack-reused 29798 Receiving objects: 100% (29817/29817), 11.04 MiB | 1.75 MiB/s, done. Resolving deltas: 100% (16973/16973), done. Checking connectivity... done.
Following that, we'll need to find the available Drush versions. This is through git tag command.
$ cd /opt/drush $ git tag 1.0.0+drupal5 1.0.0+drupal6 1.0.0-beta1+drupal5 1.0.0-beta2+drupal5 1.0.0-beta3+drupal5 1.0.0-beta4+drupal5 1.0.0-rc1+drupal5 1.0.0-rc1+drupal6 1.0.0-rc11+drupal6 1.0.0-rc2+drupal5 1.0.0-rc2+drupal6 1.0.0-rc2+drupal7 1.0.0-rc3+drupal5 1.1.0+drupal5 1.1.0+drupal6 1.2.0+drupal5 1.2.0+drupal6 1.3.0+drupal5 1.4.0+drupal5 2.0.0 2.0.0-alpha1+drupal5 2.0.0-alpha1+drupal6 2.0.0-alpha1+drupal7 2.0.0-alpha2+drupal5 2.0.0-alpha2+drupal6 2.0.0-alpha2+drupal7 2.0.0-rc1 2.1.0 3.0.0 3.0.0-alpha1 3.0.0-beta1 3.0.0-rc1 3.0.0-rc2 3.0.0-rc3 3.0.0-rc4 3.1.0 3.2.0 3.3.0 4.0.0 4.0.0-rc1 4.0.0-rc10 4.0.0-rc3 4.0.0-rc4 4.0.0-rc5 4.0.0-rc6 4.0.0-rc7 4.0.0-rc8 4.0.0-rc9 4.1.0 4.2.0 4.3.0 4.4.0 4.5.0 4.5.0-rc1 4.6.0 5.0.0 5.0.0-rc1 5.0.0-rc2 5.0.0-rc3 5.0.0-rc4 5.0.0-rc5 5.1.0 5.10.0 5.11.0 5.2.0 5.3.0 5.4.0 5.5.0 5.6.0 5.7.0 5.8.0 5.9.0 6.0.0 6.0.0-beta1 6.0.0-rc1 6.0.0-rc2 6.0.0-rc3 6.0.0-rc4 6.1.0 6.1.0-rc1 6.2.0 6.3.0 6.4.0 6.5.0 7.0.0-alpha1 7.0.0-alpha2 7.0.0-alpha3 7.0.0-alpha4 7.0.0-alpha5 7.0.0-alpha6 7.0.0-alpha7 7.0.0-alpha8 7.0.0-alpha9 debian/4.3-1 debian/4.4-1 debian/4.4-2 debian/4.5-2 debian/5.0dev-1
Let's try with version 6.5 first using the git checkout command.
$ sudo git checkout 6.5.0 Note: checking out '6.5.0'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 0a7918a... Prep for 6.5.0
Later, we need to create the soft link to the drush command and verify that our link works. Instead of using /usr/local/bin, we'll put the symbolic link to /usr/bin directory. More on this later.
$ sudo ln -s /opt/drush/drush /usr/bin/drush $ which drush /usr/local/bin/drush
Checking our Drush version.
$ drush --version Drush Version : 6.5.0
To switch another Drush version, for example version 5.1, we'll using the git checkout command again.
$ sudo git checkout 5.1.0 Previous HEAD position was 0a7918a... Prep for 6.5.0 HEAD is now at 1583e0d... Prep for 5.1 $ drush --version drush version 5.1
How about the latest version of 7. As shown below, version 7 uses Composer to install all its dependencies.
$ sudo git checkout 7.0.0-alpha9 Previous HEAD position was 1583e0d... Prep for 5.1 HEAD is now at f10919a... Prep for 7.0.0-alpha9. $ drush --version Unable to load autoload.php. Drush now requires Composer in order to install its dependencies and autoload classes. Please see README.md
Installation of Composer, dependency management for PHP is straight forward although executing downloaded Bash script directly is not recommended.
$ sudo mkdir /opt/composer $ cd /opt/composer/ $ sudo sh -c 'curl -sS https://getcomposer.org/installer | php' #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /opt/composer/composer.phar Use it: php composer.phar
Now similarly, we'll create the symbolic link for composer.phar in /usr/bin directory.
$ sudo ln -s /opt/composer/composer.phar /usr/bin/composer $ composer --version Composer version 1.0-dev (eadc167b121359986f542cc9cf976ecee3fcbf69) 2015-03-02 18:20:22
Why we need to put in /usr/bin directory instead of /usr/local/bin directory? The reason is the default $PATH for sudo command, as shown below, does not includes the /usr/local/bin directory.
$ sudo bash # echo $PATH /sbin:/bin:/usr/sbin:/usr/bin
Since we've installed Composer and satisfied the Drush version 7 dependency. We'll check our installation again.
$ cd /opt/drush $ sudo composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them. ......
Lastly, check our Drush version again.
$ drush --version Drush Version : 7.0.0-alpha9
Hence, by using Git, we can easily install and switch to different Drush version within one installation.