Home > Article > Development Tools > The difference between composer install and composer update
The following tutorial column by composer uses will introduce to you the difference between composer install and composer update. I hope it will be helpful to friends in need!
1.composer install
install command reads the composer.json file from the current directory and processes it dependencies and install them into the vendor directory.
php composer.phar install
If there is a composer.lock file in the current directory, it will read the dependency version from this file instead of based on the composer.json file. Get dependencies. 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:
composer install command (mainly) is used in production environment. The composer.lock file records the current version information of the project. When the install command is executed, the difference between each extended
version of the lock file and the latest version will be detected. If there is any Then 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.
To ensure safety
In the production environment you should only use composer require "package name: version number"
The above is the detailed content of The difference between composer install and composer update. For more information, please follow other related articles on the PHP Chinese website!