为什么 Laravel 的 Composer 创建项目执行失败?项目、Laravel、Composer

2023-09-07 09:00:05 作者:此号作废

看来,除非我使用 sudo,否则我的 composer 命令无法创建 Laravel 项目.

It appears that unless I use sudo my composer command fails to create a Laravel project.

没有 sudo 它会给我以下错误:

Without sudo it gives me the following error:

[ErrorException]                                                             
  copy(/Users/H/.composer/cache/files/laravel/laravel/73094f2633f1b90f3ef  
  6de4a8a5b610532510e0e.zip): failed to open stream: Permission denied  

我在这里错过了什么?

推荐答案

如果你曾经执行过:

sudo composer <anything>

您的一些作曲家主文件 (~/.composer/) 将由 root 编写,如果您无法删除或再次覆盖它们,除非您使用 sudo 成为 root,所以你有 2 个选项:

Some of your composer home files (~/.composer/) will be written by the root and if you can't delete or write over them again unless you use sudo to become root, so you have 2 options:

1) 将这些文件的用户改回您自己的用户:

1) Change the user of those files back to your own:

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

或者在 Mac 上

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

2) 删除整个文件夹(并丢失缓存)以从头开始:

2) Delete the whole folder (and lose your cache) to restart from scratch:

sudo rm -rf ~/.composer/cache

甚至

sudo rm -rf ~/.composer
 
精彩推荐
图片推荐