composer updates the specified dependency package method

藏色散人
Release: 2021-03-09 13:56:44
forward
3645 people have browsed it

The following tutorial column ofcomposerwill 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 therequire## of the specified dependency package

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

requireis more flexible. If it is not installed, it will be installed. If it is installed, it willupgradeordowngradeaccording to the passed version number.
updatecannot pass the specifiedversion numberon the command line. You need to manually editcomposer.jsonfirst and specify the newversion number., and then execute the update command.

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

Example

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

updatecommand Unable to specifypackage version on the command line No., you need to manually modify thecomposer.jsonfile

// 安装包 composer require hashids/hashids:2.0.0
Copy after login
Incorrect usage

composer update hashids/hashids:3.0.0
Copy after login
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
Copy after login
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 package3method to update sequentially, because
composerwill verify the integrity of the configuration filejson vs lock, you specified that you want me to updateA, but youB'sversionis inconsistent injsonandlock, but you don't want me to update it. This is problematic.

At this time, you can only use

composer updateto 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

installcan be used to install dependencies for the first time after the project is initialized, and the version number incomposer.lockwill 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.lockis equivalent to executingcomposer require packageName:versionNo, and the one that does not exist is equivalent to executingcomposer 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 installshould be executed once to synchronize the team's version changes.

So during collaborative development, we recommend uploading

composer.lock/composer.jsonto 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" }
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!