Header Ads

How to Install Composer in MacBook (Step-by-Step Guide)

If you are getting the error:


zsh: command not found: php


while installing Composer on your MacBook, don’t worry. This happens because PHP is not installed by default in newer macOS versions.


In this guide, I will show you exactly how I installed Composer on my Mac using Homebrew.


------------------------------------------------------------

Step 1: Check if Homebrew is Installed

------------------------------------------------------------


Open Terminal and run:


brew --version


If you see something like:


Homebrew 5.0.15


Then Homebrew is already installed ✅


If not, install Homebrew first from:

https://brew.sh


------------------------------------------------------------

Step 2: Install PHP

------------------------------------------------------------


Since Composer requires PHP, install PHP first:


brew install php


After installation, verify:


php -v


You should see output like:


PHP 8.5.3 (cli)

Built by Homebrew


Now PHP is successfully installed ✅


------------------------------------------------------------

Step 3: Install Composer

------------------------------------------------------------


Now install Composer using Homebrew:


brew install composer


After installation, verify:


composer --version


You should see something like:


Composer version 2.9.5

PHP version 8.5.3


That’s it 🎉 Composer is now successfully installed on your MacBook.


------------------------------------------------------------

Alternative (Manual Method - Not Recommended)

------------------------------------------------------------


Before installing PHP, if you try:


curl -sS https://getcomposer.org/installer -o composer-setup.php

php composer-setup.php


You may get this error:


zsh: command not found: php


This means PHP is not installed.


So always install PHP first using Homebrew.


------------------------------------------------------------

Final Commands Summary

------------------------------------------------------------


brew install php

php -v

brew install composer

composer --version


------------------------------------------------------------


Now you can create a Laravel project like this:


composer create-project laravel/laravel myproject


Happy Coding 🚀

No comments

Powered by Blogger.