1
votes

I want to install Laravel but again and again I got the below error,

rukon@rukon-HP-Notebook:~$ composer global require laravel/installer Changed current directory to /home/rukon/.config/composer ./composer.json is not writable. rukon@rukon-HP-Notebook:~$

I tried to make writable composer.json by

$chmod 777 ./composer.json 

but it's not working. my file owner is not root

1
to clarify, ./composer.json refers to /home/rukon/.config/composer/composer.json right?apokryfos
What have you tried to debug the problem? Can you share the current permissions of that file?Nico Haase

1 Answers

1
votes

When you run any composer global command, the composer.json used is the one at your HOME directory, not at your projects directory. E.g. at ~/.composer/composer.json.

Looks like your home directory composer is owned by root.

At some point you've executed composer with root and messed up your installation.

To find out where your composer's home directory is at, you should run this (as shown here):

composer config --list --global | grep home

E.g. given your output, it seems your home directory sits at "/home/rukon/.config/composer":

So you'd need to run:

sudo chown -R $USER: ~/.config/composer

To fix your "global" composer configuration directory.

You should be able to run composer global commands after that.

If you have more permissions problems, you'd better fix your home directory so everything in there is owned by your user, and nothing by root as shown here:

sudo find ~ -type d -user root -exec sudo chown -R $USER: {} +

For a regular installation the above should be safe (all the files in your home directory belong to to your own user), but if you have anything special in there you should probably be aware and take a more surgical approach (checking each directory).