Composer: Command Not Found on Mac - composer-php

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

Related

Laravel: [ErrorException] "continue" targeting switch is equivalent to "break". during "composer install"

When I run ...
composer install
... on a server with PHP and nginx installed.
I get the following exception:
[ErrorException]
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
How can I fix this?
This is a new warning introduced in PHP 7.3.
It means you are not allowed to have a continue statement inside of a switch, you should use break instead.
To fix this you most likely just have to update composer, this can be done simply by running composer self-update.
You can also just run php without warnings, this can be done by setting the ini config values as a start parameter.
php -d error_reporting=0 composer.phar
Check your current PHP version if it's greater than 7.2, then execute follow below simple steps
1. Disable the latest php version
sudo a2dismod php7.3
2. Restart the nginx service
sudo service nginx restart
3. If you are using Apache2 run as below
sudo service apache2 restart
4. Set alternatives
sudo update-alternatives --set php /usr/bin/php7.2
5. Check the PHP version
php -v
6. Now, Install Composer as below
composer install
Old composer uses continue statement in their code within the switch which is outdated and cannot be used anymore with latest version of php.
you need to update your composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=bin
for more details visit composer download
It was because of an outdated composer. After searching a lot finally the following works for me:
Uninstall the old composer.
Install a new updated composer.
You can download or install composer from this link: https://getcomposer.org/download/
For me,
just go to this file
sudo nano /usr/share/php/Composer/DependencyResolver/RuleSetGenerator.php
As a quick and dirty alternative, you can fix the error in that file. Just replace "continue" with "break"

Composer doesn't work after global installation

I'm a newbie. I've searched all over the place to find a solution for my issue but unfortunately couldn't find it. So hopefully somebody on here can tell me what I'm doing wrong or what I missed.
I installed composer on my local machine (MacBook Pro).
I've made it global and when I go to /usr/local/bin I can see the file composer.phar
On my desktop I've created a folder teamleader-api. I want to make a WordPress plugin that uses service API's.
As library I want to use https://github.com/sumocoders/Teamleader
On the instructions that I found they say that I need to go to my plugin directory.
$ cd /Users/myname/Desktop/teamleader-api
The library says that to install I need to use composer require sumocoders/teamleader
$ composer require sumocoders/teamleader
But when I give in this command in my terminal I get
-bash: composer: command not found
What am I doing wrong?
I found my solution....just needed to watch the next youtube video :-)
I explain what I did so people who might have the same issue in the future know what to do.
In terminal I went to my teamleader-api folder who is on my desktop.
From https://getcomposer.org/ I copied the code
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');"
Instead of composer require sumocoders/teamleader I need to use php composer.phar require sumocoders/teamleader
And now it works....easy as pie :-)

difference between composer and composer.phar

What is the difference between composer and composer.phar?
Example:
composer install
composer.phar install
Is there a reason why I keep seeing code writen using composer.phar all the time when composer does the same?
There is no difference - composer.phar is the executable and composer can be an alias or symlink for it, depending on the way you've installed composer. As rob006 pointed out, there can be multiple ways to install composer: the official documentation at https://getcomposer.org/doc/00-intro.md#globally recommends to move the downloaded PHAR file to /usr/local/bin/composer which will make it callable through composer for all users of your system.
If you would move the file to another destination, like /usr/local/bin/composer.phar, the same composer binary would be available under that different command composer.phar.
And finally, if you would not have the chance to install composer globally, you could put it under either name in any local place

Laravel package installation on live server

How to install package in laravel on live server, whenever I run "command composer require monolog/monolog". It gives error Could not open input file: /home/root/composer.phar
First of all, you should not run composer require on live server. You should only run composer install so you should require it locally, test if everything is working fine and then on live server just install library that is tested in your application.
About error:
Could not open input file: /home/root/composer.phar
make sure this file really exists (if not you can download it from Composer site) and make sure it has correct permissions (it should have execute permission) - use chmod +x composer.phar to make it executable
Please try like this.
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ php composer.phar update monolog/monolog
You can install package without any problem.

command line composer command not defined

I am following the composer developer Tutorial: https://hyperledger.github.io/composer/tutorials/developer-guide.html
Everything worked till the point when I am running from the command line:
$ composer archive create -a dist/my-network.bna --sourceType dir --sourceName .
-bash: fds: command not found
The composer command was not found. When built by npm install the script can execute the composer command within the package.json
Next I installed php composer from: https://getcomposer.org - Which might be the wrong package?
$ composer network deploy
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "network" is not defined.
My 2 questions: is this the right package, if not how can I remove it safely?
Furthermore, how can I execute the composer command.
You need to npm install -g composer-cli -- please refer to the documentation.

Resources