Skip to content
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.phar but 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.phar instead of composer).
  • 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=composer

2. Install Composer on macOS via Homebrew

brew install composer

3. 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 install

4. 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 ~/.bashrc

5. Verify the installation

composer --version
# Output: Composer version 2.7.x ...
Do I need PHP installed to use Composer?
Yes — Composer is a PHP application. You must have PHP (≥ 7.2.5) installed and accessible as php before Composer can run.
How do I update Composer after installation?
Run composer self-update to update to the latest version. Composer also auto-updates when you run composer install or composer update if new versions are available.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro