How to force Symfony to use Composer 2

712 views Asked by At

My Symfony 4.4 application was buit with Composer 1.x. Now I need to switch to Composer 2. But I'm unable to do the switch, because Symfony CLI uses Composer 1 no matter what.

I've both composer1 and composer2 installed:

# ls -la /usr/local/bin/ | grep composer
-rwxr-xr-x  1 root root  2354438 dic 31 18:06 composer
-rwxr-xr-x  1 root root  2000535 set 16 16:28 composer1

# /usr/local/bin/composer1 --version
Composer version 1.10.22 2021-04-27 13:10:45

# /usr/local/bin/composer --version
Composer version 2.2.3 2021-12-31 12:18:53

But when I run symfony composer --version, it uses composer 1.x.

Back in '20, Fabien wrote

For Symfony CLI, running symfony composer checks the version of Composer used in the composer.lock file and tries to find a Composer binary named composer1 or composer2.

So the problem is that I need to update the composer.lock of my application to use composer2. Still, I cannot find any reference to the composer versione being used.

So, as per title: how can I update my composer.lock to use Composer 2?

1

There are 1 answers

0
Dr. Gianluigi Zane Zanettini On

Ok, I found out by trial and error. It was enough to run

# /bin/php7.4 /usr/local/bin/composer update

(that's the composer2 executable).

Composer worked it's magic and now I get

# symfony composer --version
Composer version 2.2.3 2021-12-31 12:18:53