PHPnews.io

Using Both Composer 1 and Composer 2

Written by colinodell.com - Blog / Original link on Oct. 26, 2020

Composer 2 has been released with several great features and improvements! Best of all it's (mostly) backward-compatible with Composer 1. The one issue you're most likely to encounter when upgrading to Composer 2 is having Composer plugins that don't support this newer version yet.

The ideal solution would be upgrading those plugins to newer versions (or submitting a feature request to the plugin developers to support Composer 2). But if that's not feasible you can actually co-install both Composer 1 and Composer 2 by following these steps:

Step 1: Install Composer 1 separately

Assuming you already have Composer installed, this will create a copy of it called composer1:

sudo cp `which composer` /usr/local/bin/composer1 && sudo composer1 self-update --1

Step 2: Upgrade Composer to v2

If you haven't already upgraded your main composer program to v2 you can do so with this command:

composer self-update --2 # You might need to run this with "sudo"

At this point, you'll have two commands available on your machine:

Step 3: Add composer2 alias (optional)

If you'd also like to have composer2 available as a command, simply create the following symlink:

sudo ln -s `which composer` /usr/local/bin/composer2

Now you have three commands at your disposal:

colinodell

« Climate Activism in Tech: Design, Code, Hack, and Share - Learn about GitHub Actions and Unconventional Autoloaders in tomorrow’s Laravel Worldwide Meetup »