Conposer_self_update

リポジトリーを取得する際に、v2 系を使えと言われるようになったけど、composer 自体のversionアップってどうやったかな?と思ったので、メモを残しておく。

開発環境に phpmd を導入しようとしたら以下のようなメッセージが表示された。

1
2
3
4
5
6
7
8
9
$ composer require --dev phpmd/phpmd
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is now available and you should upgrade. See https://getcomposer.org/2
Using version ^2.9 for phpmd/phpmd
./composer.json has been updated
Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

composer 自体のversionアップを行う。

1
2
3
4
$ sudo composer self-update
Updating to version 2.0.4 (stable channel).
Downloading (100%)
Use composer self-update --rollback to return to version 1.8.6

バージョンが更新されたことを確認する。

1
2
$ composer --version
Composer version 2.0.4 2020-10-30 22:39:11

リポジトリーを require したところ、警告なしで導入できた。

1
2
3
4
5
6
7
8
9
$ composer require --dev friendsofphp/php-cs-fixer
Using version ^2.16 for friendsofphp/php-cs-fixer
./composer.json has been updated
Running composer update friendsofphp/php-cs-fixer
Loading composer repositories with package information
Updating dependencies
Lock file operations: 14 installs, 0 updates, 0 removals
- Locking composer/semver (3.2.2)
- Locking doctrine/annotations (1.11.1)