Composer: command not found – possible fixes

Composer is a dependency manager for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them automatically. If you’re familiar with other programming languages, Composer is somewhat similar to Ruby’s bundler, Node’s npm or Python pip.

Beginners sometimes encounter "composer: command not found" error message when they try to run Composer. This is a generic error and the real cause varies between different setups.

This article is going to show you a few common fixes to "composer: command not found" error.

Why "composer: command not found"?

If you receive the "composer: command not found" error, the composer executable binary isn’t in one of the directories listed in your PATH environment variable.

Typically, environment variables refer to variables accessible to all processes and users under the same Operating System (OS), such as Windows, macOS, and Linux. Environment variables, for instance, can be used to store systemwide values, such as PATH, TEMP or TMP.

PATH is the most popular and widely known environment variable, which stores a list of directories that contains files that can and should be executed.

Reinstall Composer

Often when a software does not work as intended, reinstalling it from scratch may be the way to go.

You don’t have to worry about system conflicts or reinstallation will overwrite anything , as "composer: command not found" indicates that the command is not recognized by the system.

The proper way to install Composer is to follow official documentation. Suppose you already have PHP on your system, run these commands in your

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

The first command downloads the installer script and saved as composer-setup.php. The remaining commands compares compare the official hash against the one you downloaded, and run the file if no inconsistency found.

These commands will certainly be changed as new version releases every once in a while. You should copy them directly from Composer homepage.

Now composer has been installed locally. If you want to install it globally, run the following command to move the composer.phar executable to /usr/local/bin.

sudo mv ./composer.phar /usr/bin/composer

Reinstall Composer with default arguments

If reinstalling Composer using official commands doesn’t work, you may try directly running composer-setup.php with the default --install-dir and --filename argument.

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

The composer-setup.php can be downloaded from

Correct Composer executable path

As a few of our readers pointed out, sometimes, people follow installation guides online which puts its executable in /usr/local/bin/composer.phar instead of /usr/local/bin/composer.

Programs that expect composer in /usr/local/bin/ or /usr/bin would not be able to find it, therefore invoking the wrong command, causing bash to raise "composer: command not found" error message. It has happened with Laravel users before.

One way to fix this is to create a symbolic link so that system calls to both path will run the same executable. Run these commands in any terminal window.

sudo ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
sudo ln -s /usr/local/bin/composer.phar /usr/bin/composer

Alternatively, you can directly rename the executable by running

sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer
sudo ln -s /usr/local/bin/composer.phar /usr/bin/composer

After that, you need to chmod the original composer.phar file and give it executable permission.

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

Then, if you like, update the composer alias by running

alias composer="php /usr/local/bin/composer"

Windows users: Use Laragon

If you’re using Windows, you should replace the whole fragmented development stack with one portable development.


Laragon is a modern, maintained and rich-featured local development environment designed for PHP and Laravel programming. It’s equipped with a Laragon Terminal that is ready to use right out of the box, without setting up Composer separately.

Click to rate this post!
[Total: 38 Average: 4.9]

Leave a Comment