Home  >  Article  >  Development Tools  >  composer updates the specified dependency package method

composer updates the specified dependency package method

藏色散人
藏色散人forward
2021-03-09 13:56:443663browse

The following tutorial column of composer will introduce you to the method of composer updating the specified dependency package. I hope it will be helpful to friends in need!

composer updates the specified dependency package method

composer updates the require## of the specified dependency package

compoesr #/update can update the specified dependency package (upgrade/downgrade).

require is more flexible. If it is not installed, it will be installed. If it is installed, it will upgrade or downgrade according to the passed version number.
update cannot pass the specified version number on the command line. You need to manually edit composer.json first and specify the new version number. , and then execute the update command.

#忽略
composer require google/protobuf --ignore-platform-reqs -vvv
require command

Example

// 安装包
composer require hashids/hashids:2.0.0
// 已安装 升级
composer require hashids/hashids:3.0.0
// 已安装 降级
composer require hashids/hashids:2.0.4
update command

updatecommand Unable to specify package version on the command line No., you need to manually modify the composer.json file

// 安装包
composer require hashids/hashids:2.0.0
Incorrect usage

composer update hashids/hashids:3.0.0
Correct usage example

vim composer.json
"require": {
    "hashids/hashids": "3.0.0"
},
:wq
#升级到3.0.0
composer update hashids/hashids

vim composer.json
"require": {
    "hashids/hashids": "2.0.4"
},
:wq
#降级到2.0.4
composer update hashids/hashids
At the same time, if we edit and update If the version numbers of multiple packages are incorrect, you cannot use


composer update package1
composer update package2
composer update package3 method to update sequentially, because
composer will verify the integrity of the configuration file json vs lock, you specified that you want me to update A, but you B's version is inconsistent in json and lock, but you don't want me to update it. This is problematic.

At this time, you can only use

composer update to update dependencies globally. Note that it is an update operation for global packages. Some packages that you have not changed but use a version number range may also be updated and upgraded. Please Use with caution!

install command

install can be used to install dependencies for the first time after the project is initialized, and the version number in composer.lock will be read first , to ensure the consistency of package versions in collaborative development as much as possible. The package version record that exists in

composer.lock is equivalent to executing composer require packageName:versionNo, and the one that does not exist is equivalent to executing composer update packageName with versionRule in composer.json.

When we collaborate on development, A installs a new dependency package locally, or updates a dependency package, which will be written to

composer.lock/composer.json, and A uploads it to the warehouse. After B is pulled to the local, composer install should be executed once to synchronize the team's version changes.

So during collaborative development, we recommend uploading

composer.lock/composer.json to the remote warehouse at the same time.

Version number range

大于/大于等于:>1.2.3 >=1.2.3
小于/小于等于:<1.2.3 <=1.2.3
确切的版本号:1.2.3 
~1.2.3: 1.2.3 <= version < 1.3
^1.2.3: 1.2.3 <= version < 2.0

{
    "php": ">=7.0",
    "ext-swoole": ">=4.0.0",
    "lib-curl": ">=7.29.0"
}

The above is the detailed content of composer updates the specified dependency package method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete