Home » Php » php – How to install Composer on macOS?

php – How to install Composer on macOS?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I was trying to install the Composer on my macOS version: high sierra--> 10.13.4

but after using the command:

sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 

It created some files and directory but it didn’t download the composer.
My terminal displayed following error:

No log handling enabled – using stderr logging

Created directory: /var/db/net-snmp

Created directory: /var/db/net-snmp/mib_indexes`

How can I resolve this problem?

How to&Answers:

First install Brew on your MAC:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then install PHP:

brew update
brew install php
brew install composer

To test installation, run:

 $ composer -V

Answer:

Install download the composer using the following curl  command in the 
terminal:

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

After the command, you will have composer.phar file in the current 
directory and the composer command is available as:

php composer.phar [composer commnad]

In order to make composer available globally, you have to move the 
recently downloaded composer.phar to local user’s bin folder as follow:

go to /usr/local/bin folder . You can click  Shift + Command + G to open 
the dialog to go to folder.

move the recently downloaded composer.phar in the usr/local/bin folder
create a alias using command  alias composer="php 
 /usr/local/bin/composer.phar"


Now, you can access the composer from the terminal simply using the 
composer  command. Thats it.