composer install 与 update区别

  • Jesse
  • 2017-09-30 11:20:43
  • 1484

composer install

如果当前目录下存在composer.lock文件,它会从此文件读取依赖版本;

如果不存在,则从 composer.json 文件去获取依赖,并在处理完依赖关系后创建 composer.lock 文件。

这确保了该库的每个使用者都能得到相同的依赖版本。

composer update

通过 composer.json 文件去获取更新依赖,更新完成后,会更新 composer.lock 文件

为了获取依赖的最新版本,并且升级 composer.lock 文件,你应该使用 update 命令。

如果你只是想更新几个包,你可以像这样分别列出它们:

composer update vendor/package1 vendor/package2

你还可以使用通配符进行批量更新:

composer update vendor/*

区别:

1.composer install:(主要)用于生产环境
composer.lock 文件记录项目当前版本信息,当执行 install 命令时,会检测 composer.lock 文件的各扩展版本与最新版本差别,如果有则更新到最新版。

2.而composer update:也会执行上述所操作
当存在 composer.lock 时,composer 会根据 composer.lock 来安装依赖,它将会省掉很多检测新版本的工作。

使用composer list 可以看到composer的命令帮助:Available commands:

about           Short information about Composer.
archive         Create an archive of this composer package.
browse          Opens the package's repository URL or homepage in your browser.
clear-cache     Clears composer's internal package cache.
clearcache      Clears composer's internal package cache.
config          Set config options.
create-project  Create new project from a package into given directory.
depends         Shows which packages cause the given package to be installed.
diagnose        Diagnoses the system to identify common errors.
dump-autoload   Dumps the autoloader.
dumpautoload    Dumps the autoloader.
exec            Execute a vendored binary/script.
global          Allows running commands in the global composer dir ($COMPOSER_HOME).
help            Displays help for a command
home            Opens the package's repository URL or homepage in your browser.
info            Show information about packages.
init            Creates a basic composer.json file in current directory.
install         Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses        Show information about licenses of dependencies.
list            Lists commands
outdated        Shows a list of installed packages that have updates available, including their latest version.
prohibits       Shows which packages prevent the given package from being installed.
remove          Removes a package from the require or require-dev.
require         Adds required packages to your composer.json and installs them.
run-script      Run the scripts defined in composer.json.
search          Search for packages.
self-update     Updates composer.phar to the latest version.
selfupdate      Updates composer.phar to the latest version.
show            Show information about packages.
status          Show a list of locally modified packages.
suggests        Show package suggestions.
update          Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate        Validates a composer.json and composer.lock.
why             Shows which packages cause the given package to be installed.
why-not         Shows which packages prevent the given package from being installed.

本文出自 亮有一技,转载时请注明出处及相应链接。