11

I installed Drush 8 with composer.

composer require drush/drush:~8

Unfortunately, error drush command not found after Drush completely installed.

Why's the drush command can't be use?

enter image description here

Installing Drush for Drupal 8 with Composer

https://www.youtube.com/watch?v=ZqY_XsCTmAc

  • Assuming your php is 5.4.5 or grater, I wonder if this "Build Failing" has something to do with your problem. – No Sssweat Jul 11 '16 at 3:47
  • @NoSssweat Thanks. How do I remove it? Is that remove the composer.json? – JJ12345 Jul 11 '16 at 3:51
  • 1
  • Then try installing Drush 9 master/dev. – No Sssweat Jul 11 '16 at 3:55
  • composer global require drush/drush:dev-master – No Sssweat Jul 11 '16 at 3:56
17

Once you have installed Drush, you need to ensure that you ~/vendor/bin directory is in your $PATH, as explained in the installation instructions (Note: this link no longer works)

Add export PATH="$HOME/.composer/vendor/bin:$PATH" to your ~/.bash_profile or ~/.bashrc, and then run source ~/.bash_profile (or ~/.bashrc).

I would recommend against installing Drush 9 via composer require at this time. Sticking with Drush 8 is probably best; if you want to use Drush 9, use a simpler installation method, such downloading the .phar, or clone the repository and run composer install in the directory Drush was cloned to.

  • 1
    I would recommend against installing Drush 9 via composer require at this time. Thanks for the info! – No Sssweat Jul 11 '16 at 4:31
  • 1
    What is the reason to against installing Drush 9 via composer require ? – Jimmy Ko Jul 24 '16 at 3:09
  • The non-stable version of Drush requires some non-stable versions of its dependencies. This can cause some complications, depending on what you are doing. Generally you get around this by setting your minimum stability, but it's simpler to just install via another method. As an aside, if you are inclined to use composer global require for anything, please see github.com/consolidation-org/cgr – greg_1_anderson Jul 24 '16 at 22:00
  • @JimmyKo The reason that a global Drush isn't recommended is that with Drush 9+, best practices recommend Drush to be installed as a dependency for Drupal. This prevents issues with a Drush version mismatch, for example. – karolus Oct 7 '18 at 23:34
  • If it still doesn't work, ` ~/.bash_profile` or ~/.bashrc might have been edited. Back it up and find a default one. – Chris Happy Apr 2 at 3:38
10

Using ssh on my server host I did add drush to my path following composer instructions: Add

    export PATH="$HOME/.composer/vendor/bin:$PATH"

to your ~/.bash_profile or ~/.bashrc, and then run source ~/.bash_profile (or ~/.bashrc)

However, I got this running

    drush status
    -bash: drush: command not found

    which composer
    /opt/cpanel/composer/bin/composer

    which drush   
    /usr/bin/which: no drush in (/home/mth/.composer/vendor/bin:/home/mth/.composer/vendor/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/mth/bin:/home/mth/bin)

Using my cPanel file manager, I found I couldn't see the hidden composer folder, though I saw other hidden folders and files (dot prefix). It turns out composer was within the .config folder. I added the new folder to my $PATH and bingo!

    export PATH="$HOME/.config/composer/vendor/bin:$PATH"   

Hours! Moral? Verify composer location.

0

You need to make sure that drush is located within your environmental PATH variable, or you can specify installation folder by setting COMPOSER_BIN_DIR, e.g.:

sudo COMPOSER_HOME=/var/lib/composer COMPOSER_BIN_DIR=/usr/local/bin COMPOSER_VENDOR_DIR=/var/lib/composer/vendor composer require drush/drush:~8

Or it's much easier to install it via Phar, e.g. on Linux:

sudo install <(curl http://files.drush.org/drush.phar) /usr/local/bin/drush

On OS X, try: brew install drush.

0

Now, although my issues were with a Composer Scaffold install for Drupal 8 which needs Drush (in this case v.9) installed as a dependency, I too was having similar issues. Even though a global Drush is no longer recommended, due to dependency issues, it's very convenient to call upon Drush from anywhere.

What I would recommend installing is Drush Launcher, which will give you the option of calling Drush from anywhere, even if you are running different projects using different versions of Drush. I have it running both locally and on my Web servers, and it's running fine there. It fixed my issues of seeing drush: command not found, even when I had projects where Composer had correctly installed Drush.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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