11

Going in circles trying to figure out the right way to install Drush on a Linux CentOS system. I have Git set up, but as I'm not planning to contribute to Drush code at the moment, it's not unambiguously clear that I should be using Git.

Some directions say to use PEAR, but when I go to the Drush project page, the directions say to get Drush 6 from Git. Tutorials I have found demo wget and PEAR, not Git. And the Git project page View says, "Use our Github project for contributing code, or reporting bugs, or requesting features," none of which applies.

Could an experienced Drupalista please answer the following?

  1. Is Git now the only method of obtaining Drush? Someone asked a similar question more than a year ago when PEAR was still recommended.
  2. If Git is the way to go, I have read that drush should not be installed within the website directories, so which directory is it recommended to be in when I invoke the following?

    git clone --branch 7.x-5.x http://git.drupal.org/project/drush.git

I'm looking forward to using Drush. Thanks!

8 Answers 8

12

Drush moved to GitHub a few weeks ago. The official home is now: https://github.com/drush-ops/drush

The current preferred method is to install with composer:

composer global require drush/drush:6.*

If you are working with Drupal 8, or need a patch that hasn't been backported, then you can work with the latest version:

composer global require drush/drush:dev-master

You can also use composer to install a particular version.

You can install it manually; and normal GitHub retrievals apply. You can download the master (link is on the main page), or clone the repo locally. When you clone locally, you can checkout any tag you want.

I have it installed in my home directory, eg

cd ~
git clone https://github.com/drush-ops/drush.git drush

After, you need to run composer

cd ~/drush
composer install

I then put ~/drush/ in my $PATH:

export PS1=$PATH:~/drush/

Everything should work as normal.

Sidenote. Even if you don't want to contribute back, tracking your whole site with git is a great way to handle dev/live, and for backing out oopsies.

2
  • This didn't seem to work for me. My understanding is you must use composer now
    – User
    Jul 9, 2014 at 21:29
  • @User composer is the recommended method right now, but you can git clone, but you need to do a composer install after. I don't recall when this became a requirement, but it happened sometime after this answer.
    – mpdonadio
    Jul 9, 2014 at 22:40
8

(1). Yes, you can still install Drush using pear. See the section "Installing - Pear" in the README.md, which is displayed on the project page: https://github.com/drush-ops/drush

To whit:

pear channel-discover pear.drush.org
pear install drush/drush

(2). If installing Drush from git, the best branch is 6.x, and the most recent tag is 6.0.0.

If you install from Pear as shown above, and you do -not- get Drush 6.0, please post a bug on the GitHub project. (Sorry, don't have time to fire up a VM and test the pear install right now, but it is presumed to work.)

Update: I missed the second question in (2). You can put it where you want. A lot of people put it in /usr/local/drush when doing a system-wide install. I usually install it per-user, in ~/local/drupal/drush. Just make sure that you also add the folder you use to your PATH. Like chrisjlee, I have an install script you may examine if you wish: https://github.com/greg-1-anderson/utiliscripts/blob/master/move-in

2
  • The pear install works fine for 6.0.0, I upgraded a legacy server to it the other day
    – Clive
    Sep 7, 2013 at 12:39
  • It seems that the channel pear.drush.org is not working any more.
    – Henrik
    Mar 30, 2016 at 11:09
3

You can try out my project. It install's drush automatically for you:

https://github.com/chrisjlee/uamp-files/blob/master/drush/setup.sh

It's rather simple. It assumes you have git installed though.

2
  • 1
    I had to replace git co with git checkout
    – frazras
    Feb 2, 2015 at 4:38
  • 1
    ya I got this as well when trying to install 'git: 'co' is not a git command. See 'git --help'. Did you mean one of these? commit clone log'
    – pal4life
    Mar 16, 2015 at 20:55
2

The package repo versions of Drush are outdated, and there were major improvements to Drush that make it a better idea to install it from the git repo. If you're keeping Drupal up to date, you should be keeping Drush up to date with it as things can break when the two are not updated together.

Drush should be installed to /usr/local/bin or /opt on most *nix systems. /opt may be better if you want to be able to backup and restore the installation and save your settings.

2

Since Version 9, Drush is installed by Composer when listed as dependency of Drupal 8. See also at docs.drush.org.


Instructions to install or upgrade a global Drush 8 (without using Git):

# Browse to https://github.com/drush-ops/drush/releases and download the drush.phar attached to the latest 8.x release.

# Test your install.
php drush.phar core-status

# Rename to `drush` instead of `php drush.phar`. Destination can be anywhere on $PATH. 
chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush

# Optional. Enrich the bash startup file with completion and aliases.
drush init

More detailed information can be found at docs.drush.org. There is also an instruction for a site-local installation.

1
  • 1
    This is how I installed it on my computer.
    – apaderno
    Mar 31, 2016 at 13:07
1

On OS X/macOS I always installed it with Homebrew. It's just brew install drush. End of story.

Only recently since D8 was released and Composer got the state of the art I also always have it installed site-locally via composer require drush/drush to make use of it in Docker containers etc. for example.


Drush 9 (D8.3+)

Actually since version 9 installing Drush with Composer is the one and only recommended way to install Drush:

Drush 9 only supports one install method. It requires that your Drupal 8 site be built with Composer and Drush be listed as a dependency.

@see http://docs.drush.org/en/master/install/


No Composer

What else you can do if you have no Composer on prod for example but at least have access to the command line, is to install Drush with Composer on a different machine, then upload the vendor/ directory and then access the Drush binary like that for example:

$ vendor/drush/drush/drush -y updb
0

Following is from https://www.drupal.org/node/2009426 :

Below is how I install Drush on CentOS systems that have H-Sphere installed as a control panel

1 - Grab a copy of Drush and untar it in your shared folder

sudo wget --quiet -O - http://ftp.drupal.org/files/projects/drush-7.x-5.9.tar.gz | sudo tar -zxf - -C /usr/local/share

(Note, change the link above you the link to the latest version of drush on Drupal.org.)

2 - Create a symbolic link to where Drush can be found on your server

sudo ln -s /usr/local/share/drush/drush /usr/local/bin/drush

3 - Get Drush to auto download the required "stuff"

sudo drush

Drush won't work yet as it won't know where to find php, so

4 - Open your bash_profile file and edit the PATH line from something like this

bash_profile: PATH=/hsphere/shared/bin:/hsphere/shared/sbin:/hsphere/local/var/vpopmail/bin:/usr/local/bin:/usr/local/sbin:$PATH:$HOME/bin

to something like this (note the php path in this version):

PATH=/hsphere/shared/bin:/hsphere/shared/sbin:/hsphere/local/var/vpopmail/bin:/usr/local/bin:/usr/local/sbin:/hsphere/shared/php53/bin:$PATH:$HOME/bin

5 - Reboot your server and YEE HAW!


With this instructions from the offical drupal site, there is absolut no need for git or any other 3rd party tools. Im perfectly fine with installing drush on my multi side vm that way.

0
0

Drush 9, which at the moment I am writing this answer is the master branch, only supports a single installation method: The Drupal 8 site must be built with Composer, and Drush be listed as dependency. Installing it globally is not supported anymore. Moshe Weitzman says it clearly in a comment at Drush 8.x doesn't install Drupal 8.4.x and Drush master doesn't install Drupal 8.3.x.

Global install of Drush is no longer supported because you get errors exactly like the one described here. The install docs already don't mention it anymore. Each project needs to name Drush as a dependency. Its fine if Drush8 sites stick with the global install and Drupal 8.3-. For Drupal 8.4, they are going to need to use Drush9 as a dependency.

The documentation for the master branch also says it in a short note.

Drush 9 (coming soon!) only supports one install method. It requires that your Drupal 8 site be built with Composer and Drush be listed as a dependency.

The note is referring to Drupal 8 because the minimum requirement for Drush 9 (which is the master branch, at this moment) is Drupal 8.3+. The Drush 8 documentation, reports the following commands as method to globally install it.

# Download latest stable release using the code below or browse to github.com/drush-ops/drush/releases.
wget http://files.drush.org/drush.phar

# Test your install.
php drush.phar core-status

# Rename to `drush` instead of `php drush.phar`. Destination can be anywhere on $PATH. 
chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush

# Optional. Enrich the bash startup file with completion and aliases.
drush init

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.