HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
Composer error in MacBook Pro sudo: php: command not found

 Composer error while setup in macbook and solution

 

 

While install composer, I am facing above error.

Command 

 

jaybharat@Jays-MacBook-Pro ~ % sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

Password:

sudo: php: command not found

zsh: command not found: php

zsh: command not found: php

zsh: command not found: php

 

Composer error screenshot here

Composer Error Screenshot here

 

 

Error above

 

Solution step 1/2:

First you have to install Homebrew

 

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Source: https://brew.sh/

 

screenshot solution1

 Installing Homebrew it is a part of the solution step 1 out of 2

 

Solution step 2/2:


jaybharat@Jays-MacBook-Pro ~ % brew install php

Second you have to install PHP

 

screenshot solution2

 

Installing PHP 2nd and last step of the solution 

 

Finally, Composer installed solved.
 

screenshot here

 

 Finally solved Composer installation

 

Some time you may face error while installing any package using composer

example below I am trying to download google SSO

jaybharat@Jays-MacBook-Pro bharatbaba.com % sudo composer require google/apiclient:"^2.0"

sudo: composer: command not found

and I was getting error as above.

So, inthis case you have to run this query

jaybharat@Jays-MacBook-Pro bharatbaba.com % which composer

composer not found

 

jaybharat@Jays-MacBook-Pro bharatbaba.com % sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { 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

jaybharat@Jays-MacBook-Pro bharatbaba.com % sudo mv composer.phar /usr/local/bin/composer

jaybharat@Jays-MacBook-Pro bharatbaba.com % which composer                               

/usr/local/bin/composer

Now the problem is solved.

 

 

 

 

 

 

 

 

   Share on Facebook

Page views:1341