103

If i type "composer" i get the above error message.

I did on my macbook:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

to install Composer globally.

I had to manually create the /local/bin/composer directory, maybe this caused the error ?

php composer.phar

works if i in my code directory where the .phar file is.

What could i do to solve the problem and run composer globally ?

My ~/.profile

export PS1="\W: "
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx

~: echo $PATH

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/bin
~: 
bobbybackblech
  • 1,868
  • 5
  • 20
  • 22

11 Answers11

320

The path /usr/local/bin/composer is not in your PATH, executables in that folder won't be found.

Delete the folder /usr/local/bin/composer, then run

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

This moves composer.phar into /usr/local/bin/ and renames it into composer (which is still an executable, not a folder).

Then just use it like:

$ composer ...
deceze
  • 510,633
  • 85
  • 743
  • 889
  • 2
    The fact that you're typing in "$" perhaps? That's just to signify your command line prompt, which typically is "$". – deceze Jul 23 '15 at 12:49
  • 1
    I'm getting a `composer: Permission denied` saw some solutions with `sudo chmod` but i'm getting `sudo: not found` (it's a synology (busybox)) – Jeroen van Langen Jul 23 '15 at 13:08
  • 5
    Maybe that is why `$` should not be included in answers. Seems obvious to us but not to new people. And it is also obvious that you don't need the `$` for people to understand that you are talking about the terminal. – JGallardo Feb 15 '16 at 23:16
  • 4
    I think including the $ is great (if you have problems understanding what the $ is for hmmm then maybe linux scripting is not for you?) – gvanto Mar 01 '16 at 00:36
  • Why is this not in the documentation on composer! Ty @deceze – Jonas de Herdt May 29 '20 at 08:37
  • @Jonas The Composer documentation doesn't advise creating any folders, and if you just follow exactly what it says, you won't see this problem at all: https://getcomposer.org/doc/00-intro.md#globally – deceze May 29 '20 at 08:40
  • After digging around. This is the only way that works for me on the mac. – Blues Clues Jul 24 '20 at 06:26
  • Yeah this works. you need to delete "composer" folder at the end of this path `/usr/local/bin/composer` then run the command `mv composer.phar /usr/local/bin/composer` – Dushan Sep 04 '20 at 16:13
  • It's helpful to have the $ in stack overflow answers to signify the beginning of the command line. – James Hubert Nov 18 '20 at 03:04
95

Well I tried a lot of things but none seemed to be working. But the following process did it right, I can now use composer command in terminal. I'm in mac OS 10.12.1

$ curl -sS https://getcomposer.org/installer | php
$ chmod +x composer.phar
$ mv composer.phar /usr/local/bin/composer
$ composer
maksbd19
  • 3,785
  • 28
  • 37
33

I get into the same issue even after moving the composer.phar to '/usr/local/bin/composer' using the following command in amazon linux.

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

I used the following command to create a alias for the composer file. So now its running globally.

alias composer='/usr/local/bin/composer'

I don't know whether this will work in OS-X. But when i search with this issue i get this link. So I'm just posting here. Hope this will help someone.

Mahendran Sakkarai
  • 8,381
  • 6
  • 44
  • 66
24

Tested on Mac OSX after installing via instructions on composer website:

sudo mv composer.phar /usr/local/bin/composer
Sabrina Leggett
  • 9,079
  • 7
  • 47
  • 50
11

This works on Ubuntu;

alias composer='/usr/local/bin/composer/composer.phar'
nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
10

Globally install Composer on OS X 10.11 El Capitan

This command will NOT work in OS X 10.11:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer 

Instead, let's write to the /usr/local/bin path for the user:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Now we can access the composer command globally, just like before.

Draken
  • 3,134
  • 13
  • 34
  • 54
Amol Gholap
  • 111
  • 1
  • 3
4

this wasted me a day or two. like why dont anybody say on tutorials that the command composer is not to be used without actually linking and stuff... I mean everyone is writing composer command like its the next step when we are not all 5 years experienced users to know these details.

cp composer.phar /usr/local/bin/composer

did it for me on ubuntu after getting stuck for 2 days

JimHawkins
  • 4,843
  • 8
  • 35
  • 55
agilewebb
  • 41
  • 3
  • Me too, followed all the tutorials and they couldn't add one tiny line or two of information about the command being moved to /usr/local/bin/composer. They all say to run something like run "export PATH="$HOME/.composer/vendor/bin:$PATH"" and it does not fix it! – Michael Falciglia Feb 20 '21 at 20:41
2

This worked fine for me this time in the permissions issue.

alias composer="php /usr/local/bin/composer/composer.phar"
Ashwani Garg
  • 1,479
  • 1
  • 16
  • 22
0

On Mac OS X, for anyone having:

-bash: /usr/local/bin/composer: Permission denied

problem, while trying to move downloaded composer.phar using:

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

this is the cause:

System Integrity Protection

and this is the solution:

  1. Reboot in recovery mode: restart you mac and hold down cmd+R.
  2. Open the terminal once recovery mode has started via Utilities>Terminal via the bar at the top.
  3. Type in csrutil disable and hit enter. You should see a msg returned saying that:

    the System Integrity Protection is off.

  4. Restart the computer as normal and then go set up composer. I had to put it in /usr/bin and NOT /usr/local/bin because for some reason it just didn't work there.
  5. Go back to recovery mode and enable System Integrity Protector by typing csrutil enable
  6. Come back in normal boot up and check that composer works. It did for me.

The above 6 steps are copied from here, so all the credit belongs to the user Vasheer there.

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
0

If you have to run composer with sudo, you should change the directory of composer to

/usr/bin

this was tested on Centos8.

Başar Söker
  • 606
  • 8
  • 16
0

Composer is avialble and install the packages in the global path but they are not available in the shell, Mac in my case. I managed to fix this by adding the global bin to the path at my bash file.

Steps:

First, check what is your home directory by typing in the shell:

cd ~
pwd

this will tell you the home path

The next step is to verify that composer set the global directory there:

ls -al .composer

If you got list of files that's mean composer set up the directory, if not - look above or in the documentation.

The next step is to edit the bash profile. Mine is ~/.bash_profile but other can ~/.zshrc. If you don't have any one like this try to see how to set up aliases and place the the code in aliases file:

PATH="YOUR_HOME_PATH/.composer/vendor/bin:${PATH}"
export PATH

That's it! just reload the file with

source PATH_TO_FILE

And you good to go!

Roy Segall
  • 336
  • 2
  • 6