安装 Laravel 时出现错误:“./composer.json 不可写。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41448659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When installing Laravel i got an error: "./composer.json is not writable."
提问by Dimitar
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.
我正在运行 Ubuntu 16.04 LTS 和 PHP 7 以及 Composer 1.3.0 版,并从我的主文件夹运行此命令。
回答by PelleLV
Check the owner of composer.json.
检查 composer.json 的所有者。
ls -lh ~/.composer/composer.json
If it's 'root', run:
如果是“root”,请运行:
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.
在 .composer 文件夹中,检查“缓存”文件夹所有者。如果是“root”,请重新运行上面的命令,但将 composer.json 切换到缓存。否则,您最终可能会收到“无法创建缓存目录”警告。
回答by Alexey Mezenin
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
回答by Divyesh pal
I think this code is missing in your composer file which doesn't allows Packagist to find the package of Laravel.
我认为您的作曲家文件中缺少此代码,它不允许 Packagist 找到 Laravel 的包。
Put this is in your composer.json
file and try again:
把它放在你的composer.json
文件中,然后再试一次:
"repositories": {
"packagist": { "url": "https://packagist.org", "type": "composer" }
}
回答by mohamed elshazly
Check the owner of composer.json.
检查 composer.json 的所有者。
ls -lh /home/<yourusername>/composer.json
If it's 'root', run:
如果是“root”,请运行:
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.
在 .composer 文件夹中,检查“缓存”文件夹所有者。如果是“root”,请重新运行上面的命令,但将 composer.json 切换到缓存。否则,您可能会收到“无法创建缓存目录”警告。
回答by azurecorn
Your command is being ran as vagrant
user, which hasn't enough permissions.
您的命令正在以vagrant
用户身份运行,该用户没有足够的权限。
It can be run as www-data user:
它可以作为 www-data 用户运行:
sudo -u www-data composer global require "laravel/installer"
sudo -u www-data composer global require "laravel/installer"
回答by ztvmark
sudo composer global package_name
Example:
例子:
sudo composer global require "laravel/installer"
your password
你的密码
enter
进入
回答by Angga Ari Wijaya
You can run with sudo
privilege without change folder permission because you install in global.
您可以在sudo
没有更改文件夹权限的情况下以特权运行,因为您安装在全局中。