The first paragraph of the answer by @Eric Negaard well explains why it fails.
And the answer by @Hermann Schwarz should work well for a project-specific drush.
Here is how to deal with it if you are using global drush in you environment (and maybe Drupal 7).
If you follow the standard installation procedure of drush
, you are probably using the tool cgr developed by Greg Anderson (see justification) to manage your global drush
.
Then, cgr update drush/drush
would do a job, which updates drush to say, 10.4.2 as of 2021-04-14, providing you are using Drupal 8 or above. However, this command would not work well with Drupal 7, because Drush Version 10 (or 9) does not support Drupal 7.
If you are using Drupal 7, do as follows - basically you must uninstall drush first and reinstall your desired version.
cgr remove drush/drush
cgr drush/drush:8.4.6
where 8.4.6
is the latest (or your chosen) version of drush Ver.8. See drush-ops/drush Releases on Github to check out the latest releases.
For your information,
cgr info drush/drush | grep -i versions
would return the version of your cgr-installed drush (In my environment, when its version was 10, it did not match with the result of drush --version
, which confused me).