Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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?

like image 554
Macejkou Avatar asked Mar 10 '15 09:03

Macejkou


3 Answers

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
like image 177
Abdes Avatar answered Nov 07 '22 04:11

Abdes


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.

like image 30
Garrett R. Davis Avatar answered Nov 07 '22 02:11

Garrett R. Davis


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 :)

like image 1
Oluwatobi Samuel Omisakin Avatar answered Nov 07 '22 02:11

Oluwatobi Samuel Omisakin