Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nicoeg's avatar

sh: composer: command not found

I know that there are a million threads on this problem, and at this point I believe I've tried every single one.

The problem happens whenever I call the Laravel installer: laravel new app.

When I call composer create-project --prefer-dist laravel/laravel app everything works fine.

I'm using zsh and my path looks like this: export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.composer/vendor/bin:$PATH".

What could possibly be the reason for this not working?

0 likes
17 replies
bashy's avatar

Show us this and we can go from there;

type composer
Nicoeg's avatar

composer is /usr/local/bin/composer

bashy's avatar

Okay. I would remove $HOME/.composer/vendor/bin and test

Nicoeg's avatar

Just tried it without success.

ejdelmonico's avatar

In your .zshrc, it should be /Users/your-home-name/.composer/vendor/bin Writing it that way works for my installation. I had a similar issue with using the $HOME variable.

zfi's avatar

If I may bump this issue, I have encountered the same set of circumstances.

I have a fresh installation of macOS 10.12.2; Installed both laravel/installer and laravel/valet. The composer.phar is installed in the /usr/local/bin/directory. I have created an alias to run composer.

composer is aliased to `php /usr/local/bin/composer.phar'

Running

laravel new blog

generates this response

Crafting application...
sh: composer: command not found
Application ready! Build something amazing.

The site does not run. In order to get the site to work, I had to run these additional steps:

cd blog
composer install —no-scripts
cp .env.example .env
php artisan key:generate

If I create the site using composer, the site works as expected.

composer create-project --prefer-dist laravel/laravel blog

I am fairly certain that the error from composer: command not found is where .env file is created and keyed. It is also where the dependancies are installed. Does anyone have thoughts on where to begin to troubleshoot this?

1 like
zfi's avatar
zfi
Best Answer
Level 7

It appears that using an alias for composer is not the right thing to do. I removed the alias and then renamed /usr/local/bin/composer.phar to /usr/local/bin/composer. Now running 'laravel new blog' runs without any errors. The new site has a .env file and a defined site key.

11 likes
brkaydn's avatar

Thank you zfi! But you can use the alias after renaming /usr/local/bin/composer.phar to /usr/local/bin/composer. Edit your alias with alias composer="php /usr/local/bin/composer"

2 likes
T0ny's avatar

Thanks zfi and brkaydn I ran exactly into the same issue today on my Mac OSx (10.13.1) Here is my solution that might help another one:

mv /usr/local/bin/composer.phar /usr/local/bin/composer

Then update the alias in the ~/.bash_profile from

alias composer="php /usr/local/bin/composer.phar" to: alias composer="php /usr/local/bin/composer"

Thanks guys

12 likes
mariohbrino's avatar

I did install composer in my macOS 10.13.6 and follow the instructions you guys give, but I still don't have access to composer when I use alias without file composer.phar.

Please, can someone help? Thanks.

  • [x] Install composer
  • [x] Move composer to /usr/local/bin/composer
  • [x] Add alias into ~/.bash_profile
  • [x] Test commands
# Install
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Move
mv composer.phar /usr/local/bin/composer

Add alias with file composer.phar into ~/.bash_profile

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

Running

composer --version

generates this response

Composer version 1.7.2 2018-08-16 16:57:12

Running

laravel new project-name

generates this response

Crafting application...
sh: composer: command not found
Application ready! Build something amazing.

Change alias without file composer.phar into ~/.bash_profile

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

Running

imac server $ composer --version

generates this response, no action

imac server $

Running

imac server $ cd project-name
imac server $ composer install

generates this response, this don't install any dependencies

imac server $
mariohbrino's avatar

I was been install the composer as /usr/local/bin/composer/composer.phar when I should to install /usr/local/bin/composer that's why the alias did not work.

Install and setup composer into /usr/local/bin with name composer

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

Add alias into ~/.bash_profile

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

1 like
Chimsy's avatar

Thanks TONY, Found myself in the same problem and your problem helped me. I was on MAC OS Catalina.

renoirtech's avatar

Hey people, I've had this problem today and here's what I've done

  1. Removed every existing composer files and folders from my system.
  2. Reinstalled composer via brew composer install brew
  3. Tha dá. It worked! Now im able to run ` laravel new with success
nomikz's avatar

It is better to as T0ny suggested.

mv /usr/local/bin/composer.phar /usr/local/bin/composer

you rename from composer.phar to composer. Then you need to update the alias in ~/.bash_profile To do that you need to (macos) cd ~/ nano .bash_profile change composer.phar to composer control+x save y

1 like

Please or to participate in this conversation.