1. Download Composer

First, download Composer by running the official installation script. Visit the Composer website and copy the provided install command (typically a four-line script).

Paste it into your terminal and execute it. This will download composer.phar into the current directory.

2. Move Composer to a Global Location

To use Composer globally, move the composer.phar file to /usr/local/bin/ and rename it to composer:

mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

3. Ensure /usr/local/bin is in Your PATH

To make sure you can run composer from anywhere, confirm that /usr/local/bin is in your system's PATH.

Check your shell type:

Run the following command to verify your shell:

echo $SHELL

Update the correct profile file:

4. Verify Composer Installation

Restart your terminal and check that Composer is accessible globally by running:

composer -V

This should display the installed Composer version.

Why Use the PATH Method?

Adding /usr/local/bin to your PATH ensures a more consistent experience when running globally installed tools. Unlike using an alias, this method allows scripts and other tools to call composer without issues.

Now you can use Composer anywhere by simply running:

composer install