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?
Installing Drush for Drupal 8 with Composer
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
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)
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.
Using ssh on my server host I did add drush to my path following composer instructions: Add
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!
Hours! Moral? Verify composer location.
You need to make sure that
drush is located within your environmental
PATH variable, or you can specify installation folder by setting
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.
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.