0

From my project root, where composer.json and composer.lock are, I tell composer to require drush/drush. It seems to do what it should, but upon completion it seems drush is not installed.

$ composer require drush/drush
Using version ^8.1 for drush/drush
./composer.json has been updated
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing webmozart/path-util (2.3.0)
    Downloading: 100%         

  - Installing symfony/var-dumper (v2.8.13)
    Downloading: 100%         

  - Installing jakub-onderka/php-console-color (0.1)
    Downloading: 100%         

  - Installing jakub-onderka/php-console-highlighter (v0.3.2)
    Downloading: 100%         

  - Installing dnoegel/php-xdg-base-dir (0.1)
    Downloading: 100%         

  - Installing nikic/php-parser (v2.1.1)
    Downloading: 100%         

  - Installing psy/psysh (v0.7.2)
    Downloading: 100%         

  - Installing pear/console_table (v1.3.0)
    Downloading: 100%         

  - Installing consolidation/output-formatters (1.1.0)
    Downloading: 100%         

  - Installing consolidation/annotated-command (1.4.1)
    Downloading: 100%         

  - Installing drush/drush (8.1.5)
    Downloading: 100%         

Writing lock file
Generating autoload files
> DrupalProject\composer\ScriptHandler::createRequiredFiles

$ drush
The program 'drush' is currently not installed. You can install it by typing:
sudo apt install drush
1

2 Answers 2

1

Well, actually you installed it locally. You can find it in your project's directory under vendor/drush/drush place (maybe, it depends where the composer put it). You can call only from that place because it's not in your global path. If you want to use this method, you need to call it with an absolute or relative route. Like if your composer installed to here:

On Windows: D:/phptest/my_project/vendor/drush/drush

On Linux: ~/my_project/vendor/drush/drush

and you are in the D:/phptest/my_project (Windows) or ~/my_project (Linux) dir, in that case, you need to call it like:

On Windows: vendor/drush/drush --version OR D:/phptest/my_project/vendor/drush/drush --version

On Linux: vendor/drush/drush --version OR ~/my_project/vendor/drush/drush --version

and you will get something like:

Drush Version : 8.1.3

Of course for this, you need a PHP in the global path. (so you need to be able to call PHP from anywhere.)

If you installed it globally with composer (I think you just installed it locally), in that case maybe you need to create a (soft) symlink one place which is globally available for you (listed in the %PATH% variable on windows or in the $PATH variable on Linux), or you need to add the drush's dir to your global path variable.

I suggest you, install it globally, like here is written: https://docs.drush.org/en/8.x/install/

# 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

Then you can use it in any site's dir.

TIPP: if you're installing drush launcher (https://github.com/drush-ops/drush-launcher) globally, then you can have per-site base different drush installed. In this case, you don't need to have global drush installed.

2
  • I know this is an old comment, but I came to it looking for some Drush help. The above link to /en/master/install is no longer active. Anyone new to this and looking for the current link for installation instructions, its found here: docs.drush.org/en/8.x/install. Enjoy. :-)
    – Drew
    Aug 7, 2020 at 13:06
  • @Drew Thanks, I've updated my answer and also I've extended it. Aug 19, 2020 at 14:04
0

Since you didn't use the --global option, Composer installed Drush in the vendor directory. More precisely, the Drush executable is on vendor/bin. If I run vendor/bin/drush status, I get the following output.

Drupal version : 8.2.1
Site URI : http://default
Database driver : sqlite
Database name : sites/default/files/.ht.sqlite
Drupal bootstrap : Successful
Drupal user :
Default theme : bartik
Administration theme : seven
PHP executable : /usr/local/bin/php
PHP configuration : /usr/local/etc/php/7.0/php.ini
PHP OS : Darwin
Drush script : /Library/Server/Web/Data/Sites/Default/vendor/drush/drush/drush.php
Drush version : 8.1.5
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Install profile : standard
Drupal root : /Library/Server/Web/Data/Sites/Default
Drupal Settings File : sites/default/settings.php
Site path : sites/default
File directory path : sites/default/files
Temporary file directory path : /tmp
Sync config path : sites/default/files/config_Dy0z5R0mB3fLiKC_f8qR1UcV4HkXFeohO3KKXBcYUTWrsxunPXpZbezfqd39 mz4u0G7LVAYSmg/sync

I normally read they suggest installing Drush as you did, but you can also install it globally, with composer --global require drush/drush. On macOS Sierra, using that command installs Drush in ~/.composer/vendor/bin, which I then need to add to the Bash PATH with the following command.

if [ -d $HOME/.composer/vendor/bin ]; then
    export PATH=$PATH:$HOME/.composer/vendor/bin
fi

I didn't install Drush globally, but I added those lines in ~/.bash_profile, in the case I globally install other commands with Composer.

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.