Drupal 8 - Drush composerRequireDrupal8 error System: Ubuntu 14.x

Drupal: 8.x

Drush: 8.x

I recently have installed Drush using composer global require drush/drush:dev-master code and it got installed successfully.

I ran command which drush and the terminal gave me the path /home/ravi/.composer/vendor/bin/drush. 

The problem is, I am not able to execute any commands from project root. It gives me below error:

PHP Fatal error:  Cannot redeclare composerRequireDrupal8() (previously declared in /var/lib/composer/vendor/composer/autoload_real.php:63) in /var/www/html/study/drupal/8/vendor/composer/autoload_real.php on line 70


But when I execute below command from project root:

/home/ravi/.composer/vendor/bin/drush status


then Drush works perfectly well.

Is there any way I can use Drush from project root? Or have I made any mistakes in installation? Please help.

PS: I have tried updating composer and composer self-update but it did not help.
Please do not install Drush using composer global require.


Quoted from http://docs.drush.org/en/8.x/install-alternative/.

If you have Drupal 8 installed conventionally best practice would be to install Drush 8 globally by downloading the latest drush.phar, see http://docs.drush.org/en/8.x/install/.

If your Drupal 8 site is composer based then Drush 9 is probably already included. If not see http://docs.drush.org/en/master/install/.