laravel new sh: composer: command not found - laravel

The problem happens whenever I call the Laravel installer: laravel new app.
I get sh: composer: command not found
When I call composer create-project --prefer-dist laravel/laravel app everything works fine.
I'm using zsh and my export paths looks as follows:
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/opt/homebrew/bin:$PATH
export ZSH="/Users/konstantinkrumov/.oh-my-zsh"
export PATH=~/.composer/vendor/bin:$PATH
I also have an alias for composer
alias composer="php /usr/local/bin/composer/composer.phar
When I run which composer I get: composer:
aliased to php /usr/local/bin/composer/composer.phar
So far I have tried to:
Move composer.phar into /usr/local/bin/
Reinstalled composer
Changed the alias path to php /usr/local/bin/composer/composer
Tried making a symlink as suggested in this stackoverflow question
non of the above seem to work

The best solution which I was able to find was to make a function in the ~/.zshrc file.
Function looks like this:
ln() {
composer create-project --prefer-dist laravel/laravel $1;
}
This way I can run ln app and generate a new laravel app with a shorter syntax.
I was unable to figure out why running laravel new app gave the following output: sh: composer: command not found and failed to generate a new app.

If you are on macOS, You can do:
cd /usr/local/bin
mv composer.phar composer
sudo chmod +x composer

Related

Why laravel installer returns command not found?

I try to install new laravel app on fresh ubuntu installation, but I got error :
master#master-laptop:/mnt/_work_sdb8/wwwroot/lar$ composer global require "laravel/installer=~1.1"
Changed current directory to /home/master/.config/composer
./composer.json has been updated
Running composer update laravel/installer
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
13 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
master#master-laptop:/mnt/_work_sdb8/wwwroot/lar$ export PATH="$PATH:~/.composer/vendor/bin"
master#master-laptop:/mnt/_work_sdb8/wwwroot/lar$ laravel new NewLivewireApp --jet
laravel: command not found
Why I got error ? Is 1.1 valid installation for mopdern laravel app?
Thanks!
you must add a composer autoloader to your OS path.
add this code to the end if you are using Linux.
export PATH="$HOME/.composer/vendor/bin:$PATH"
File:
~/.bashrc or ~/.zshrc
I find it easier to just use composers built in installer, which i use on a regularly basis.
composer create-project laravel/laravel your-app
composer create-project foo/bar command creates a new project from packagist.org
composer require foo/bar gets the module(library) from packagist.org
so you should use
composer create-project laravel/laravel mylaravelproject
for detail look at this link
https://packagist.org/packages/laravel/laravel
composer global require laravel/installer
laravel new example-app
I salved the issue with commands :
nano ~/.bash_profile
export PATH=~/.composer/vendor/bin:$PATH
source ~/.bash_profile
and it works for me !

Unable to create new Laravel project

What I'm trying to accomplish:
Create a new Laravel project
What I'm trying:
I've been trying to follow the installation instructions
sudo composer global require laravel/installer
export PATH="/home/hedwin/.composer/vendor/bin:$PATH"
When I try to run the following command:
sudo Laravel new trainingLaravel
it returns this error:
sudo: laravel: command not found
You can see my picture for details : Terminal
I'm on ubuntu 18.04.
Thanks a lot for every help..
edit : problem unsolved, i completely remove laravel/installer
composer global remove laravel/installer
then i redo installation in /home/hedwin/ directory :
https://gist.github.com/zunayed93/80ba8611a88623c20f9bb6c7b4e25792
but my way to add /vendor/bin dir. to the path didn't work so i follow instructions at Laravel PHP Command Not Found
"Ok, I did that and it works:
nano ~/.bash_profile
And paste
export PATH=~/.composer/vendor/bin:$PATH
do source ~/.bash_profile
"
and finally command laravel new something works !
found solution :
sudo chown -R hedwin ~/.composer/composer.json
sudo chown -R hedwin /home/hedwin/.composer/cache/repo/https---repo.packagist.org/
sudo chown -R hedwin /home/hedwin/.composer/cache/files/
or :
"sudo chown -R hedwin ~/.composer/" is the same
sources :
When installing Laravel i got an error: "./composer.json is not writable."
Cannot create cache directory .. or directory is not writable. Proceeding without cache in Laravel

Composer: Command Not Found on Mac

I have installed Composer as per the instructions command not found
After installing I get the prompt that Composer is successfully installed but when I go to check the version it gives me error "Composer: Command Not Found"
I have been looking how to fix this issue and I had to read and understand little bit and the environment variables on MAC.
I understand the issue looks simple but it will get over complicated if you didn't understand how to install composer probably.
Solution 1
I found this solution here: https://duvien.com/blog/installing-composer-mac-osx
Open a terminal and navigate to your user directory, ie cd /User//
Run this command shown below to download Composer. This will create a Phar (PHP Archive) file called composer.phar:
curl -sS https://getcomposer.org/installer | php
Now we move composer.phar file to a directory
sudo mv composer.phar /usr/local/bin/
We want to run Composer with having to be root al the time, so we need to change the permissions:
sudo chmod 755 /usr/local/bin/composer.phar
Next, we need to let Bash know where to execute Composer:
nano ~/.bash_profile
Add this line below to bash_profile and save
alias composer="php /usr/local/bin/composer.phar"
and then run this command:
source ~/.bash_profile
Finally, run:
composer --version
Solution 2:
I understand that the first command you will find online when you try to google this issue would be
curl -sS https://getcomposer.org/installer | php
But actually this is the main terminal installation but sometimes I wanted to manually install the composer, so this 2nd solution about manually installing the composer in specific directory
First of all you need to understand where are you now on the terminal
use
pwd
and then install composer manually using the following commands
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') ==='baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt';
unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
to use it on that case you will read on the terminal to use this composer installation use
Use it: php composer.phar
so just write
php composer.phar
and it should be working.... one more thing, during this installation you can install the composer to specific directory / project folder... in that case you can use a flag with command No.4 to tell the terminal to install the composer in specific directory...this flag is --install-dir=your-directory-path
and you will the terminal this time after installing composer asking you to use the following path to call the composer
Use it: php /Users/muatafa/composer.phar
if you want to read more about this issue, I think you must read the composer documentation how to install it>>> https://getcomposer.org/download/
that's how I solved my current issue... if you still have any issues comment on this replay & Hopefully we can figure it out!
I had the same problem. "composer require something" works if installed in global and not locally.
If you install composer locally you'll then install dependencies using "php composer.phar require nameofyoudependency"
To install globally open a terminal to install as mentionned on the composer website. Then run "sudo mv composer.phar /usr/local/bin/composer"
Now you can use "composer" directly to install dependencies like => "composer require something/sdk"
the composer you installed is still named /usr/local/bin/composer.phar - look in the second yellow/brownish line in your output. Just rename it to just composer
Your composer command is not set to path, use
export PATH=$PATH:/usr/local/bin/
I had the same issue, After installing composer using the command line on their website. I forgot to put composer.phar into a directory on my PATH, so it can simply be called from any directory (Global install). and then I ran this command "sudo mv composer.phar /usr/local/bin/composer" and it was resolved
I figured out. in place of "composer require twilio/sdk" I needed to use
"composer.phar require twilio/sdk" since I am on mac. It worked

creating new laravel application on mac by laravel installer

I have been strugling to create an application with laravel installer from terminal.
I have globally installed composer and laravel..
however i constantly get this error:
If you check at the bottom of the screenshot you can see -bash: new: command not found however laravel command is being executed perfectly. My osx version is 10.10.2. Macbook pro.
Any help will be appreciated.
Another question (bit out of the topic)
Is git inbuild in mac osx?
Cuz i hadn't installed it but it shows all of its commands.
Regards,
=======================
I created alias for composer and laravel in .bash_profile and .bashrc and it worked however now I'm getting this error :
Prajwols-MacBook-Pro:htdocs prajwol$ laravel new test
Crafting application...
Warning: ZipArchive::extractTo(): Invalid or unitialized Zip object in /Users/prajwol/.composer/vendor/laravel/installer/src/NewCommand.php on line 99
Warning: ZipArchive::close(): Invalid or unitialized Zip object in /Users/prajwol/.composer/vendor/laravel/installer/src/NewCommand.php on line 101
Application ready! Build something amazing.
Result : An empty folder is created called test in destination folder.
The command needs a project name: laravel new <NAME>. Like laravel new blog. This will create a new laravel project in a new blog directory in the current path.
$ brew tap homebrew/homebrew-php
$ brew install php72
Install composer
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Install Laravel
$ composer global require "laravel/installer"
$ composer global -vvv require "laravel/installer"
now run command
composer

Composer could not find the config file: C:\Users\Username\AppData\Roaming\Composer\vendor\bin

I cannot seem to install Laravel using the following command: composer create-project laravel/laravel laravel-testing --prefer-dist as it keeps throwing the following error:
[InvalidArgumentException]
Composer could not find the config file: C:\Users\Kieran\AppData\Roaming\Co
mposer\vendor\bin
To initialize a project, please create a composer.json file as described in
the http://getcomposer.org/ "Getting Started" section
The vendor and bin folders did not exist in the below path, so I created the folders vendor and then bin inside that but still no luck:
C:\Users\Kieran\AppData\Roaming\Composer\vendor\bin
What am I doing wrong?
I managed to fix this problem. I had to delete the composerenvironment variable. Which can be found here: Control Panel>System>Edit the system environment variables>Environment variables>composer>delete
After I deleted this I could run the command I wanted with out any errors and it worked as expected: composer create-project laravel/laravel laravel-testing --prefer-dist
Enter composer in your "cmd".
You will get all the command line there. All you have to do is type
composer init.
And the rest you can set up just as explained in the instructions.

Resources