sh: composer: command not found

Published 1 year ago by Nicoeg

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?

Best Answer (As Selected By Nicoeg)
zfi

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.

bashy
bashy
1 year ago (1,091,860 XP)

Show us this and we can go from there;

type composer
Nicoeg
Nicoeg
1 year ago (23,500 XP)

composer is /usr/local/bin/composer

bashy
bashy
1 year ago (1,091,860 XP)

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

Nicoeg
Nicoeg
1 year ago (23,500 XP)

Just tried it without success.

ejdelmonico

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.

bashy
bashy
1 year ago (1,091,860 XP)

@ejdelmonico You can test that by doing this in shell;

echo $HOME
Nicoeg
Nicoeg
1 year ago (23,500 XP)

@ejdelmonico Didn't work for me.. echo $HOME returns /Users/nicolaj

zfi
zfi
11 months ago (5,690 XP)

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?

zfi
zfi
11 months ago (5,690 XP)

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.

brkaydn

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"

T0ny

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

Please sign in or create an account to participate in this conversation.