When installing Laravel i got an error: “./compose

2020-05-25 03:24发布

问题:

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.

回答1:

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.



回答2:

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:

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


回答4:

Check the owner of composer.json.

ls -lh /home/<yourusername>/composer.json

If it's 'root', run:

sudo chown -R yourusername:yourusername /home/<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 cache. Otherwise you may end up with a 'Cannot create cache directory' warning.



回答5:

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"



回答6:

sudo composer global package_name

Example:

sudo composer global require "laravel/installer"

your password

enter



回答7:

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