The composer is a dependency manager that helps in managing any third-party packages and libraries. If you are working on any PHP framework then the composer plays a major role. You can install the required libraries inside the application. It is an open-source tool and is available for all platforms like Windows, Linux, and MacOS. If you are working on a Laravel project then it is required to set up a Laravel project and also for handling the dependencies. Today, we will see how to install composer in MacOS. We already covered composer installation in Linux and Windows. So, let’s start the post to install composer in MacOS system.
Prerequisites
In order to install composer in MacOS, you will be required to have a Mac system ready. Also, you will require PHP installed in the system.
- MacOS
- Terminal with Sudo Privileges
- PHP
Once you are ready then let’s start the installation.
Install Composer in MacOS
At the very first step, you have to open the terminal and make sure you don’t have the composer installed. In order to check that just enter the below command.
composer --version
The command will return the version of the composer if it is installed. Otherwise, it will return the below response.
Now, we will be installing the composer by following the steps shown below.
Recommended: How to Install XAMPP in MacOS For PHP and MySQL Setup
Add Composer Setup in MacOS
Initially, you need to add the composer package using the below command.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
After adding the package, you will need to verify whether it is added successfully.
Verify Added Setup
To verify the package, just hit the below command in the terminal.
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
The above command will return the response based on the verification of added package.
Run Composer Setup in MacOS
Next, you need to add the below command in order to run the composer setup.
php composer-setup.php
The command will install the composer in your system.
The composer is installed in the system. But, still, it is not accessible. Let’s check that in the below response.
In order to make it accessible, you will have to add composer.phar
in the composer installed path.
Add composer.phar to Path to Make it Accessible
If you want to make the composer accessible globally in your system, you have to add composer.phar
to the composer directory. Hence, at last, you need to hit the below command.
sudo mv composer.phar /usr/local/bin/composer
This will move composer.phar to the local composer directory.
It’s done now. You can check the composer version and composer help command to check the details about the composer commands.
That’s it for this post. Now, you can proceed to Laravel or another framework setup for PHP development.
Leave a Reply