php composer update 和 composer install 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33052195/
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
What are the differences between composer update and composer install?
提问by Dawlatzai Ghousi
What are the differences between composer update
and composer install
?
composer update
和之间有什么区别composer install
?
回答by Moppo
composer update
作曲家更新
composer update
will update your depencencies as they are specified in composer.json
composer update
将更新您的依赖项,因为它们在 composer.json
For example, if you require this package as a dependency:
例如,如果您需要此包作为依赖项:
"mockery/mockery": "0.9.*",
and you have actually installed the 0.9.1
version of the package, running composer update
will cause an upgrade of this package (for example to 0.9.2
, if it's already been released)
并且您实际上已经安装了0.9.1
该软件包的版本,运行composer update
将导致此软件包升级(例如升级到0.9.2
,如果它已经发布)
in detail composer update
will:
详细composer update
将:
- Read
composer.json
- Remove installed packages that are no more required in
composer.json
- Check the availability of the latest versions of your required packages
- Install the latest versions of your packages
- Update
composer.lock
to store the installed packages version
- 读
composer.json
- 删除不再需要的已安装包
composer.json
- 检查所需软件包的最新版本的可用性
- 安装最新版本的软件包
- 更新
composer.lock
以存储已安装的软件包版本
composer install
作曲家安装
composer install
will not update anything; it will just install all the dependencies as specified in the composer.lock
file
composer install
不会更新任何东西;它只会安装composer.lock
文件中指定的所有依赖项
In detail:
详细:
- Check if
composer.lock
file exists (if not, runcomposer-update
and create it) - Read
composer.lock
file - Install the packages specified in the
composer.lock
file
- 检查
composer.lock
文件是否存在(如果不存在,运行composer-update
并创建它) - 读取
composer.lock
文件 - 安装
composer.lock
文件中指定的包
When to install and when to update
何时安装和何时更新
composer update
is mostly used in the 'development phase', to upgrade our project packages according to what we have specified in thecomposer.json
file,composer install
is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer.lock file created by composer update.
composer update
主要用于“开发阶段”,根据我们在composer.json
文件中指定的内容升级我们的项目包,composer install
主要用于“部署阶段”,在生产服务器或测试环境上安装我们的应用程序,使用存储在 composer.lock 文件中的相同依赖项,由 composer update 创建。
回答by Tim Sheehan
When you run composer install
it will look for a lock file and install whatever is contained in it, if it can't find one, it'll read composer.json
, install its dependencies and generate a lockfile.
当您运行时,composer install
它会寻找一个锁定文件并安装其中包含的任何内容,如果找不到,它将读取composer.json
、安装其依赖项并生成一个锁定文件。
When you run composer update
it simply reads composer.json
, installs the dependencies and updates the lockfile (or creates a new lockfile).
当您运行composer update
它时,它只是读取composer.json
、安装依赖项并更新锁文件(或创建一个新的锁文件)。
回答by kenorb
composer install
composer install
- If
composer.lock
does exist.- Processes and installs dependencies from the
composer.lock
file.
- Processes and installs dependencies from the
- If
composer.lock
does notexist.- Process package installs from
composer.json
. - Creates the
composer.lock
file based on the installed packages.
- Process package installs from
- 如果
composer.lock
确实存在。- 从
composer.lock
文件处理和安装依赖项。
- 从
- 如果
composer.lock
确实不存在。- 进程包从
composer.json
. composer.lock
根据已安装的软件包创建文件。
- 进程包从
As per: composer help install
:
根据composer help install
::
The install command reads the
composer.lock
file from the current directory, processes it, and downloads and installs all the libraries and dependencies outlined in that file. If the file does not exist it will look forcomposer.json
and do the same.
install 命令
composer.lock
从当前目录读取文件,对其进行处理,然后下载并安装该文件中列出的所有库和依赖项。如果该文件不存在,它将查找composer.json
并执行相同的操作。
composer update
composer update
- Processes dependencies from the
composer.json
file (installs, updates and removes). - Creates or updates the
composer.lock
file according to the changes.
- 处理
composer.json
文件中的依赖项(安装、更新和删除)。 composer.lock
根据更改创建或更新文件。
As per: composer help update
:
根据composer help update
::
The update command reads the
composer.json
file from the current directory, processes it, and updates, removes or installs all the dependencies.
update 命令
composer.json
从当前目录读取文件,对其进行处理,然后更新、删除或安装所有依赖项。
See also: Composer: It's All About the Lock File
另请参阅:作曲家:一切都与锁定文件有关
回答by Mayank Dudakiya
The best difference between composer update
and composer install
composer update
和之间的最佳区别composer install
composer install
作曲家安装
To add dependencies you need to add it manually to the composer.json file.
要添加依赖项,您需要手动将其添加到 composer.json 文件中。
If composer.lock file exists, install exactly what's specificated on this file
如果 composer.lock 文件存在,请完全安装此文件中指定的内容
- Otherwise read composer.json file to look out what dependencies needs to be installed
- Write the composer.lock with the information of the project (installed dependencies)
- 否则阅读 composer.json 文件以查看需要安装哪些依赖项
- 用项目的信息(已安装的依赖项)编写composer.lock
Not any component will be updated with this command.
不会使用此命令更新任何组件。
composer update
作曲家更新
To add or remove dependencies you need to add it manually to the composer.json file
要添加或删除依赖项,您需要手动将其添加到 composer.json 文件中
- The composer.lock file will be ignored
- composer.json file dependencies will be installed and updated (if a dependency is not installed it will be downloaded)
- composer.lock 文件将被忽略
- 将安装和更新 composer.json 文件依赖项(如果未安装依赖项,它将被下载)
If you can't (or don't know how to add or remove a library which is in fact easy,just add the name of the dependency and version in the require property of the file) modify the composer.json file manually or you prefer use the command line instead, composer has special functions for this :
如果您不能(或不知道如何添加或删除一个库,这实际上很简单,只需在文件的 require 属性中添加依赖项和版本的名称)手动修改 composer.json 文件,或者您更喜欢使用命令行,composer 对此具有特殊功能:
composer require
作曲家要求
For example if we want to add a dependency with the command line we will simply execute
例如,如果我们想使用命令行添加依赖项,我们将简单地执行
composer require twig/twig
composer require twig/twig
- composer.json file will be modified automatically and the new dependency will be added
- the dependency will be downloaded to the project
- composer.json 文件将被自动修改并添加新的依赖项
- 依赖项将被下载到项目中
composer remove
作曲家删除
If you want to remove an unused dependency we will execute simply :
如果您想删除未使用的依赖项,我们将简单地执行:
composer remove twig/twig --update-with-dependencies
composer remove twig/twig --update-with-dependencies
- Twig will be removed with all his dependencies
- Twig 将与他的所有依赖项一起被删除
回答by Phan Van Linh
composer install
作曲家安装
if(composer.lock existed){
installs dependency with EXACT version in composer.lock file
} else {
installs dependency with LATEST version in composer.json
generate the composer.lock file
}
composer update
作曲家更新
composer update = remove composer.lock -> composer install
Why we need 2 commands. I think it can explain by composer.lock.
为什么我们需要 2 个命令。我认为它可以通过composer.lock来解释。
Imagine, we DON'Thave composer.lock
and in composer.json
, there is a dependency "monolog/monolog": "1.0.*"
or "monolog/monolog": "^1.0"
.
Then, it will have some cases
试想一下,我们不要有composer.lock
和composer.json
,有一种依赖"monolog/monolog": "1.0.*"
或"monolog/monolog": "^1.0"
。
那么,就会有一些情况
- We working well today with current dependency version (eg:1.0.0) but a few months later, the dependency update (eg:1.0.1) and it possible have some bug
- Another team member may have a different dependency version if they run
composer install
in a different time.
- 我们今天使用当前的依赖版本(例如:1.0.0)运行良好,但几个月后,依赖更新(例如:1.0.1)可能有一些错误
- 如果另一个团队成员
composer install
在不同的时间运行,他们可能有不同的依赖版本。
What if we always use an EXACT version in composer.json
such as "monolog/monolog": "1.0.1"
?
We still need composer.lock
because composer.json
only track the main version of your dependency, it can not track the version of dependencies of dependency.
如果我们总是用一个确切的版本composer.json
,如"monolog/monolog": "1.0.1"
?
我们仍然需要,composer.lock
因为composer.json
只跟踪你的依赖的主版本,它不能跟踪依赖的依赖版本。
What if all dependencies of dependency also use the EXACT version?
Imagine you begin with ALL dependencies which use the EXACT version then you don't care about composer.lock
. However, a few months later, you add a new dependency (or update old dependency), and the dependencies of this dependency don't use the EXACT version. Then it's better to care composer.lock
at the beginning.
如果所有依赖的依赖也使用 EXACT 版本怎么办?
想象一下,您从使用 EXACT 版本的所有依赖项开始,然后您不关心composer.lock
. 但是,几个月后,您添加了一个新的依赖项(或更新了旧的依赖项),而这个依赖项的依赖项并没有使用 EXACT 版本。那么最好composer.lock
一开始就关心。
Besides that, there is an advantage of a semantic version over an exact version. We may update the dependency many times during development and library often have some small change such as bug fix. Then it is easier to upgrade dependency which uses semantic version.
除此之外,语义版本优于精确版本。我们在开发过程中可能会多次更新依赖项,并且库经常会有一些小的更改,例如错误修复。然后更容易升级使用语义版本的依赖项。