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:
- For macOS 10.15+ (Catalina and later), the default shell is
zsh
. - For macOS 10.14 and earlier, the default shell is
bash
.
Run the following command to verify your shell:
echo $SHELL
Update the correct profile file:
-
If you're using zsh (default on macOS 10.15+), update
~/.zshrc
:echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc -
If you're using bash (default on older macOS versions), update
~/.bash_profile
:echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
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
Leave a comment