Skip to content

Document how to most easily make vendor/bin/drush available as drush #5828

@gitressa

Description

@gitressa

Is your feature request related to a problem? Please describe.

The vast majority of Drupal sites use Drush on a Linux server. After installing Drush, you need to manually add it to the $PATH, or else you need to use vendor/bin/drush, which is not ideal.

Describe the solution you'd like

After installing Drush, it would be awesome if you could use the command drush, without any extra steps, but this is not possible, since the Drush folder needs to be added to the $PATH manually. But we could look for alternative solutions, or expand the documentation.

Additional context

drupal.org issue: https://www.drupal.org/project/ideas/issues/3405516

Possible solutions

Add in a Bash shell script file such as ~/.bashrc, and source it to take effect.

Using $PATH
Add Drush folder to $PATH (reset with source /etc/profile)

PATH=$PATH:./vendor/bin

If there's only one Drupal installation on the system, you can add the absolute path to the Drush folder, and now call drush from anywhere.

PATH=$PATH:/path/to/project/vendor/bin

Function with Git
Use Git with a function, to allow running drush inside sub-folders, shared by chx. May only work with absolute Drush path registered in $PATH (remove with unset -f drush).

function drush () {
  $(git rev-parse --show-toplevel)/vendor/bin/drush "$@"
}

Not recommended (alias)

alias drush='vendor/bin/drush': This may seem like a simple and good solution, but Drush will sometimes call itself via exec. When it does this, Drush expects that drush will be in the $PATH. If you use an alias, this redispatch might not work correctly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions