composer update install require 三个命令的的别
1.当前项目没有vendor目录、 composer.json和ccomposer.lock文件
- composer update
S D:\phpstudy_pro\WWW\aa> composer update Composer could not find a composer.json file in D:\phpstudy_pro\WWW\aa To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
没有任何执行结果
- composer require
PS D:\phpstudy_pro\WWW\aa> composer require Search for a package
生成composer.json文件,目前没有下载依赖包,接下来通过Search for package安装monolog/monolog
PS D:\phpstudy_pro\WWW\aa> composer require Search for a package: monolog/monolog //输入要安装的依赖包
Enter the version constraint to require (or leave blank to use the latest version): 1.1.* //输入版本号
Search for a package: ./composer.json has been created Running composer update monolog/monolog Loading composer repositories with package information Updating dependencies Lock file operations: 1 install, 0 updates, 0 removals - Locking monolog/monolog (1.1.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing monolog/monolog (1.1.0): Extracting archive 1 package suggestions were added by new dependencies, use `composer suggest` to see details. Generating autoload files PS D:\phpstudy_pro\WWW\aa>
项目根目录生成了vendor目录,composer.json和ccomposer.lock文件
- composer install
PS D:\phpstudy_pro\WWW\aa> composer install Composer could not find a composer.json file in D:\phpstudy_pro\WWW\aa To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section PS D:\phpstudy_pro\WWW\aa>
没有composer.json无法安装
2.只有composer.json的情况
- composer update
PS D:\phpstudy_pro\WWW\aa> composer update
新生成vendor和composer.lock
- composer reqiuire
PS D:\phpstudy_pro\WWW\aa> composer require Search for a package: // 这里直接回车不安装任何依赖
新生成 vendor、composer.lock
- composer install
PS D:\phpstudy_pro\WWW\aa> composer install
提示composer.lock缺失,原因是install命令是根据composer.lock文件安装依赖包, 所以建议使用composer update命令,但是这个命令仍然生成了vendor composer.lock文件。