How to Install Composer on MacOS – TecAdmin

The PHP Composer is a package management tool. It removes the hassle of maintaining PHP packages for an application manually. You can easily install all the required packages using Composer. It maintains a list of required packages in a JSON file called composer.json.

Advertisement

This tutorial helps you to install and configure PHP composer on macOS operating system.

install composer on macos

1. Prerequisites

  • Shell access to a running macOS
  • PHP 5.3 or higher version must be installed

2. Install Composer on macOS

Download the composer binary file from the getcomposer.org website by running the following command. It will create a file named composer.phar in the current directory.

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

Now, copy this composer.phar file under bin directory to make available anywhere in the system. Also, set the execute permission on file. I have changed the filename from composer.phar to composer for the easy use.

mkdir -p /usr/local/bin mv composer.phar /usr/local/bin/composer chmod +x /usr/local/bin/composer 

Run composer command on the command prompt. This will provide you with composer version details along with options available with the composer command.

composer    ______  / ____/___  ____ ___  ____  ____  ________  _____ / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___// /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/                    /_/Composer version 2.3.5 2022-04-13 16:43:00Usage:  command [options] [arguments]Options:  -h, --help                     Display help for the given command. When no command is given display help for the list command  -q, --quiet                    Do not output any message  -V, --version                  Display this application version      --ansi|--no-ansi           Force (or disable --no-ansi) ANSI output  -n, --no-interaction           Do not ask any interactive question      --profile                  Display timing and memory usage information      --no-plugins               Whether to disable plugins.      --no-scripts               Skips the execution of all scripts defined in composer.json file.  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.      --no-cache                 Prevent use of the cache  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

3. Upgrade PHP Composer

The PHP composer provides a command-line option (self-update) to upgrade itself. You can simply run the below command from the terminal to upgrade compose on your macOS.

sudo composer self-update 

4. Uninstall (Remove) PHP Composer

As the composer is configured with a single file, you can simply remove it from your system.

sudo rm /usr/local/bin/composer 

Conclusion

This tutorial helped you to install the PHP composer on the macOS system. That will help you to manage the dependencies of a PHP-based application.

Xổ số miền Bắc