Magento 2 Fatal Error when running composer:install

This was an issue with Composer, By installing latest version of Composer solved it. The bug for the constant variable PRE_COMMAND_RUN is raised and closed.


You need install latest version of composer, upgrade steps given below.

-- Remove existing composer

Debian/Ubuntu

sudo apt-get remove composer

Centos/Redhat

sudo yum remove composer

Get the latest composer using wget.

cd /tmp
sudo curl -sS https://getcomposer.org/installer | php

Move composer executable to PATH so it can be accessible globally.

sudo mv composer.phar /usr/local/bin/composer

To check the composer version

composer -V

You have to reinstall the Composer and use the latest composer version

To do that you can follow the following steps:

Step #1) Remove the current composer:

sudo apt-get remove composer

Step #2) install the composer , you can using following commands

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

then to make sure you have the latest Composer , run the following command

php composer.phar -V

Now, your ready to install Magento, to install Magento via composer :

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition YourProjectName

if the project folder name is exist , remove the folder and try again to install magento