通常,执行Do not run Composer as root/super user! See https://getcomposer.org/root for details
时会遇到问题sudo composer require somePackage
。
这是我安装swiftmailer的记录。
首先在没有composer require somePackage
的情况下执行sudo
。
debian9@machine:~$ composer require "swiftmailer/swiftmailer:^6.0"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Installation failed, reverting ./composer.json to its original content.
[RuntimeException]
/home/debian9/vendor/doctrine/lexer does not exist and could not be created
.
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...
让我们尝试sudo。
debian9@machine:~$ sudo composer require "swiftmailer/swiftmailer:^6.0"
Do not run Composer as root/super user! See https://getcomposer.org/root for details
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing doctrine/lexer (v1.0.1)
Downloading: 100%
- Installing egulias/email-validator (2.1.6)
Downloading: 100%
- Installing swiftmailer/swiftmailer (v6.1.3)
Downloading: 100%
egulias/email-validator suggests installing ext-intl (PHP Internationalization Libraries are required to use the SpoofChecking validation)
swiftmailer/swiftmailer suggests installing ext-intl (Needed to support internationalized email addresses)
swiftmailer/swiftmailer suggests installing true/punycode (Needed to support internationalized email addresses, if ext-intl is not installed)
Writing lock file
Generating autoload files
我很困惑,如果没有sudo
,则无法安装swiftmailer,而有了sudo
,则会发生Do not run Composer as root/super user!
的错误。
答案 0 :(得分:1)
您过去可能曾经使用sudo
运行Composer。这已将某些目录保留在vendor/
下,由root拥有,从而使您无法正常使用Composer。
将整个vendor
目录的所有权更改为您的Shell用户,或完全删除该目录。 (您将需要以root用户身份执行此操作。)完成后,您应该能够正常使用Composer。