28

This is the command I run:

composer global require "laravel/installer"

and this is the text and error I got after that:

Changed current directory to /home/dimitar/.composer
./composer.json is not writable.

I'm running Ubuntu 16.04 LTS and PHP 7 and Composer version 1.3.0 and running this command from my home folder.

8 Answers 8

51

Check the owner of composer.json.

ls -lh ~/.composer/composer.json

If it's 'root', run:

sudo chown -R yourusername:yourusername ~/.composer/composer.json

While in the .composer folder, check the 'cache' folder owner. If it's 'root', re-run above command but switch composer.json to the cache. Otherwise, you may end up with a 'Cannot create cache directory' warning.

Sign up to request clarification or add additional context in comments.

2 Comments

l believe changing the whole .composer file to be the owner would be the best thing. To avoid future error like when install laravel you can get into issues when the script may try to write something to like the vendor file. sudo chown -R yourusername:yourusername .composer
Dont need to typing -R flag if u try to set permissions on one file
5

The error says it all, there is a problem with permissions. I guess easiest way to fix this is running this command:

sudo chmod -R 775 /home/dimitar

3 Comments

Try 777, but do not do this on production server.
it worked! thanks a lot!! i can bring it back to 775 permissions after the installation, right?
I'm not sure mate, but you can try and if it'll brake something, do 777 again. )
2

I think this code is missing in your composer file which doesn't allows Packagist to find the package of Laravel.

Put this is in your composer.json file and try again:

"repositories": {
    "packagist": { "url": "https://packagist.org", "type": "composer" }
 }

Comments

0

Your command is being ran as vagrant user, which hasn't enough permissions.

It can be run as www-data user:

sudo -u www-data composer global require "laravel/installer"

Comments

0

anther case. if you are using dual boot operating system make sure other operating system is shut down/power off properly. for instance in my case if windows 10 is hibernated this error will happen to ubuntu os

Comments

0

You are not the file owner, however, you can change it by typing on your console the following command

 sudo chown -R ~/.composer/composer.json

Comments

-4
sudo composer global package_name

Example:

sudo composer global require "laravel/installer"

your password

enter

2 Comments

Yes, its just a case of needing to use: sudo.
Don't run composer with sudo. It will give the plugin or whatever you're installing full access to root and that is a potential security issue.
-6

You can run with sudo privilege without change folder permission because you install in global.

2 Comments

Doesn't even allow.
Do not run Composer as root/super user! See getcomposer.org/root for details Everybody can see this shit after typing sudo composer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.