OSX -bash: composer: command not found

155,530

Solution 1

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 ...

Solution 2

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

Solution 3

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.

Solution 4

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

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

Solution 5

This works on Ubuntu;

alias composer='/usr/local/bin/composer/composer.phar'
Share:
155,530

Related videos on Youtube

bobbybackblech
Author by

bobbybackblech

Updated on July 08, 2022

Comments

  • bobbybackblech
    bobbybackblech almost 2 years

    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
    ~: 
    
    • Droppy
      Droppy almost 10 years
      chmod 0755 /usr/local/bin/composer and add /usr/local/bin to $PATH in ~/.bash_profile. This is basic user stuff and does not belong here.
    • bobbybackblech
      bobbybackblech almost 10 years
      What exactly should i add to my .profile ? I updated my post with the content of my .profile
    • Gromski
      Gromski almost 10 years
      So composer is now at /usr/local/bin/composer/composer.phar?
    • Peyman Mohamadpour
      Peyman Mohamadpour almost 8 years
      Same problem on mac os x 10.11.4 here with /usr/local/bin & /usr/local/bin/composer in the $PATH, still getting -bash: /usr/local/bin/composer/composer.phar: Permission denied
    • Ashwani Garg
      Ashwani Garg over 2 years
      @Pmpr Have you got any solution for permissions issue?
    • Peyman Mohamadpour
      Peyman Mohamadpour over 2 years
      @AshwaniGarg Sorry, but dont remember that anymore.
  • Gromski
    Gromski almost 9 years
    The fact that you're typing in "$" perhaps? That's just to signify your command line prompt, which typically is "$".
  • Jeroen van Langen
    Jeroen van Langen almost 9 years
    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))
  • JGallardo
    JGallardo about 8 years
    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.
  • gvanto
    gvanto about 8 years
    I think including the $ is great (if you have problems understanding what the $ is for hmmm then maybe linux scripting is not for you?)
  • Sanjay
    Sanjay over 7 years
    Yea it worked after creating alias. alias composer='/usr/local/bin/composer'
  • theprojectabot
    theprojectabot over 7 years
    You should chmod +x the binary instead of just turning off your csrutil ...
  • greendino
    greendino about 4 years
    you should restart your terminal once you had done this
  • lovecoding
    lovecoding almost 4 years
    Great article! I have been searched a lot for this.
  • Jonas de Herdt
    Jonas de Herdt almost 4 years
    Why is this not in the documentation on composer! Ty @deceze
  • Gromski
    Gromski almost 4 years
    @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: getcomposer.org/doc/00-intro.md#globally
  • Saitama
    Saitama almost 4 years
    After digging around. This is the only way that works for me on the mac.
  • Dushan
    Dushan over 3 years
    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
  • James Hubert
    James Hubert over 3 years
    It's helpful to have the $ in stack overflow answers to signify the beginning of the command line.
  • Ashwani Garg
    Ashwani Garg over 3 years
    I tried this on MacOS M1, working like charm and saved my lot of time. Thanks for the solution
  • Mohamed23gharbi
    Mohamed23gharbi over 3 years
    @lone_coder you made my day, in fact I was stuck, and the solution was as simple as just restarting the terminal
  • Michael Falciglia
    Michael Falciglia about 3 years
    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!
  • Ashwani Garg
    Ashwani Garg over 2 years
    zsh: permission denied: composer
  • Sean H
    Sean H about 2 years
    I get php: command not found
  • Arslan Ramay
    Arslan Ramay about 2 years
    Works perfect on MacOS Monterey. Thanks!