composer: command not found
composer: command not found
DodaTech
2 min read
The “composer: command not found” error means your shell cannot locate the Composer executable. Composer is the dependency manager for PHP, and this error prevents you from installing or updating packages.
What It Means
Composer is a PHP application distributed as a PHAR archive. It works either by running php composer.phar directly or by installing a global composer wrapper script. The “command not found” error means neither the wrapper script nor the PHAR file is reachable through your system’s PATH.
Why It Happens
- Composer has never been installed on your system.
- You downloaded
composer.pharbut did not make it executable or move it to a PATH directory. - Composer was installed globally but the installation directory is not in your PATH.
- You installed Composer via a package manager but the binary is named differently (e.g.,
composer.pharinstead ofcomposer). - You are on a shared hosting environment where Composer is not available.
How to Fix It
1. Install Composer globally (Linux / macOS)
# Download the installer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# Verify and install globally
php composer-setup.php --install-dir=/usr/local/bin --filename=composer2. Install Composer on macOS via Homebrew
brew install composer3. Use composer.phar directly
If you cannot install globally, run Composer through PHP:
# Download composer.phar to your project directory
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
# Run it with PHP
php composer.phar install4. Add Composer’s directory to PATH
If you already installed Composer locally but get the error:
# Move it to a PATH directory
mv composer.phar ~/.local/bin/composer
# Add to PATH in ~/.bashrc
export PATH="$PATH:$HOME/.local/bin"
source ~/.bashrc5. Verify the installation
composer --version
# Output: Composer version 2.7.x ... Previous
Command CompileSwiftSources failed with a nonzero exit code
Next
Cyclic reference involving ...
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro