'permission denied for composer in /usr/local/bin/

I followed the documentation on https://getcomposer.org/doc/00-intro.md#globally to install composer globally on arch linux. When I do composer self-update, I get this message:

  [ErrorException]                                                                                    
  rename(/home/hannes/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied 

The permissions in /usr/local/bin/ (I changed them to 777, but it did not help):

-rwxrwxrwx  1 hannes users 1104202 30. Mai 18:07 composer

In my home directory I did this:

sudo chmod -R 777 .composer/

In /etc/php/php.ini, the open_basedir looks so:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/usr/local/bin/

I also tried sudo composer self-update but it did not work as well and is possibly not the right way. (?). What else could I try to make this work?



Solution 1:[1]

Now, there is a package for composer in arch linux which works for me:

sudo pacman -S composer

Solution 2:[2]

On Ubuntu server >= 16.04

FIRST

sudo rm /usr/local/bin/composer

AND

cd ~/.cache/composer
chmod 755 composer-temp.phar
sudo mv composer-temp.phar /usr/local/bin/composer

Solution 3:[3]

this might be the case if you have downloaded composer.phar directly ,

but not by running php composer-setup.php

make composer.phar executable with following command before moving it to /usr/local/bin/composer or after moving

sudo chmod 755 composer.phar

composer-setup.php will make this change for us by default

Solution 4:[4]

You should check the permissions of the directory /usr/local/bin/, not just the file within. The process has to write both, the file and into the directory which both must be granted.

Apart from that, a general hint: do not always set everything to 777. There is no reason for that and it makes your system vulnerable.

According to the line you posted in the last comment the directory is currently writeable only for the root user himself. That would explain the error you get. You should not make your own user account the owner, Linux systems are multi user environments. Instead think about one of these approaches:

  • add the account that is meant to execute the composer to the group root (a user account can belong to several groups) and make the directory group writeable
  • change the groups ownership of the directory to a group that account is a member of and make the directory group writeable
  • use the sudo utility to install and update the composer utility

The last option is the typically chosen and preferred one. It leaves permissions as they are (conservative) and only uses raised privileges for system maintenance jobs like installation and upgrade.

Solution 5:[5]

Use sudo command for any command which writes to root files of folder. It worked for me.

use sudo "your command"

Solution 6:[6]

Even after moving the file via sudo mv composer.phar /usr/local/bin/composer I was getting a permission error when trying to run the composer command. sudo chmod 755 /usr/local/bin/composer fixed things for me.

Solution 7:[7]

You could temporarily add the rights to your working user, then update composer w/o errors and then get back the rights.

sudo chmod 777 /usr/bin/
composer self-update
sudo chmod 755 /usr/bin/

Solution 8:[8]

This did the job for me on Centos 7

chown -R apache:apache path/to/composer
chmod 755 path/to/composer

Solution 9:[9]

make sure composer already at /usr/local/bin and then do following things

chmod 755 composer

if permission denied, add sudo

Solution 10:[10]

My solution on macOs was the following:

First delete the directory yo created. Somehing like '/usr/local/bin/composer' using this command: rmdir /usr/local/bin/composer.

Now try to install composer again using Homebrew :

Step 1: brew install composer. Step 2: brew link composer.

Now you can run composer in terminal.

Solution 11:[11]

For those who are using shared server here are the steps.

Let's first download composer file.

  • cd ~
  • curl -sS https://getcomposer.org/installer | php

Now we can access composer by:

  • ~/composer.phar

Assuming you have /public_html in root directory, here are the steps to use latest composer.

  • cd public_html
  • ~/composer.phar update

In future, if you want to update composer:

  • ~/composer.phar self-update

Hope this is helpful.

Solution 12:[12]

if permission denied you should use the command with sudo like:

sudo composer self-update