Home  >  Article  >  Development Tools  >  composer update install difference

composer update install difference

藏色散人
藏色散人Original
2019-08-28 13:25:137020browse

composer update install difference

composer update install difference

1.composer install

The install command reads the composer.json file from the current directory, handles dependencies, and installs it into the vendor directory.

php composer.phar install

If the composer.lock file exists in the current directory, it will read the dependency version from this file instead of obtaining the dependency from the composer.json file. This ensures that every consumer of the library gets the same dependency version.

If there is no composer.lock file, composer will create it after handling the dependencies.

2.composer update

In order to obtain the latest version of dependencies and upgrade the composer.lock file, you should use the update command.

php composer.phar update

This will resolve all dependencies of the project and write the exact version number to composer.lock.

If you just want to update a few packages, you can list them individually like this:

php composer.phar update vendor/package vendor/package2

You can also use wildcards for batch updates:

php composer.phar update vendor/*

Difference:

The composer install command is (mainly) used in the production environment. The composer.lock file records the current version information of the project. When the install command is executed, the difference between each version of the lock file and the latest version will be detected. If so, update to the latest version. The composer update command will also perform the above, but if you add the library to the require field in the composer.json file, you must use the composer update command. But at this time, the contents of other libraries will be updated. At this time, if you only add a certain library without updating other libraries (such as the production environment), you must use the composer require "package name: version number" command.

composer init --require=Package name: version number -n can also automatically update the composer.json file.

My humble opinion is that the expression is not very good. I hope the experts I have seen can add to it to deepen my understanding.

Note: This install command will give priority to resolving dependencies based on the version in the lock file, and will not do update checks or read the version number in json, so that every user of the library can Both can get the same dependency version. Therefore, it is strongly recommended to submit the lock file when submitting the project. The update command will check for updates and update the version number in the lock file.

For more technical articles on composer usage, please visit the composer usage tutorial column!

The above is the detailed content of composer update install difference. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn