Search code examples
drupal-8drush

How to use drush which is installed by composer as project dependency (Drupal 8)


I have drush added to composer.json file and I do see drush folder inside root of my drupal 8 project but I don't know how to call it?


Solution

  • So, first if you don't have drush inside your composer.json file you have to add it.

    From console run:

    composer require drush/drush
    

    After that composer will add drush files. Now, even some config files are inside drush dir at top of your project, drush file it self, the one you should call is located at vendor/bin, so you can call it i.e. like:

    vendor/bin/drush status
    

    But if you don't like to type this "vendor/bin/", but just "drush" run once:

    vendor/bin/drush init
    

    This command will edit some bash config file (/home/user_name/.bashrc) and add path of drush executable to it so it will be found when calling only by name. You wouldn't have to type full path to it any more. Basically, you could also manually edit that file, but why bothering when drush can do it for you. Or again, if you don't trust drush do it your self - in my case, after running drush init my prompt started to look a bit different.

    At end you'll probably have to run:

    source /home/user_name/.bashrc
    

    so changes added to .bashrc file take effect.