Macejkou
Macejkou

Reputation: 686

"sudo composer" command works but "composer" is not?

This is going to be easy one I guess. On my OS X - Yosemite I have copied composer.phar to my /usr/bin directory. I have been using it for a while but today I needed to run "composer update". It didnt work of course so I ran "sudo composer update". Then I got the message "command composer not found". Chmm

I copied composer to /usr/local/bin according to the documentation and now "sudo composer" works like charm. BUT when I run "composer" without sudo, it still uses the old one in "/usr/bin" directory. So I deleted it.

Now composer works only with sudo command. I get "Could not open input file: /usr/bin/composer.phar" otherwise. What should I do to point command "composer" to the new location in /usr/local/bin?

Upvotes: 8

Views: 15333

Answers (5)

Abdes
Abdes

Reputation: 996

Another alternative to get a nice composer command instead of composer.phar:

$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
$ ln -s /usr/local/bin/composer.phar /usr/local/bin/composer

Upvotes: 8

cmc
cmc

Reputation: 130

Judging from other answers it seems the solution can vary depending on your system. This is how I fixed the problem on Mac 10.12.

My composer executable in /usr/local/bin/composer had a different group than ~/.composer/ config and cache files.

/usr/local/bin/composer myusr admin ~/.composer/ myusr staff

The primary group for myusr is staff so I changed the group for /usr/local/bin/composer to staff.

/usr/local/bin myusr$ chgrp staff composer

Cache files that had been created when running composer as sudo in the past were still causing problems so I deleted those. Composer cache files are located here: ~/.composer/cache/

If updating hangs during composer update for a project check/empty cache files in the .composer directory for the project.

Upvotes: 0

omitobi
omitobi

Reputation: 7334

Okay, I encountered issues of having to run composer commands with sudo as well, but in order to get it working without throwing this kind of error (in Ubuntu 15.10):

[ErrorException]
copy(/home/randomuser/.composer/cache/files/barryvdh/laravel-cors/056068736ff8f002514178e1416c7665732eaddc.zip): failed to open stream: Permission denied

What simply solved the issue for me is:

  • Navigating to my home directory $ cd
  • Changing the ownership of .composer with: sudo chown -R $USER:$USER .composer/
  • Then composer install works smoothly.

PS: this might be different for other situation.

Hope this helps :)

Upvotes: 1

Abdallah Elsabeeh
Abdallah Elsabeeh

Reputation: 616

i will answer you how i solve it in my Ubuntu 16.10 and you can compare yours my composer folder set in

/home/abdallah/.composer/

i only give this file the 777 permission so can be reached by any user group

sudo chmod -R 777 /home/abdallah/.composer/

and that is it i hope this helpful for you

Upvotes: 0

Garrett R. Davis
Garrett R. Davis

Reputation: 339

Edit:

/etc/bashrc

Add this to that file:

alias composer="php /usr/local/bin/composer"

run:

source /etc/bashrc

Composer should now run without sudo.

Upvotes: 6

Related Questions