Installing Composer 1 and Composer 2 on the Same Host Machine

It can be really exciting when something new comes out. And man, let me tell you, I was super excited when Composer 2 dropped last year! I’ve been using it daily ever since.

Having said that, anytime a new version of something comes out, there are sometimes projects that aren’t able to update to support that new thing for whatever, totally legit reason. This creates a bit of a conundrum for people (like me) who have already done the update. Do you try and force that project to update (not always viable) or do you downgrade to work on that project (not a great answer)?

The problem with the above scenario is that neither is a great solution, but something has to be done in order to get the work done.

What if there was a third option? What if you could use Composer 2 AND Composer 1 that way neither of the “bad” options happen? Well good news! There is a way to do this (and this article is all about how).

A quick note: ideally, updating to Composer 2 isn’t that hard and I talk about it here. But not everyone can do this so, if you can’t, read one!

How to Install Composer 1 and 2 Simultaneously

Remember, that Composer is ultimately just a binary on your host machine / inside your VM. This means that the name of it is completely arbitrary and while most people probably have named their one and only compose binary “composer” you don’t have to do so.

If you have a look at the composer install instructions, basically you have to download the binary and then move it into your bin folder. It’s pretty easy! You also typically rename the composer.phar file at this stage to just be composer.

So the trick here is this:

Go ahead and install composer 2 if you haven’t already. This can be done by:

  1. Downloading composer’s phar file (see https://getcomposer.org/download/).

  2. Moving that composer.phar to the appropriate location (see https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos for Mac and Linux and https://getcomposer.org/doc/00-intro.md#installation-windows for Windows.)

Then, we are going to repeat the steps above for composer 1. If you notice on the Downloads page you can specifically download the latest composer 1 binary. Do that!

Then, when you go to move the binary for composer 1, make sure you rename it to something else. Some people I work with have specific composer2 and composer1 binaries. Personally, I prefer to keep my “default” composer to be the most current (so composer 2) and then have a separate composer1 binary for my composer1 needs.

On my machine, here’s the difference!

composer --version
Composer version 2.0.8 2020-12-03 17:20:38

vs.

composer1 --version
Composer version 1.10.20 2021-01-27 15:41:06

And that’s all there is to it! Super easy, takes just a couple of minutes to do and the end result is that you can now work on *any composer codebase.

In Conclusion

At this point, Composer 2 really is quite stable and safe to use. It’s incredibly easy to do the update and in almost all cases what you “really” need to update is all the composer plugins that your dependencies depend on. So hopefully, in most cases, the update will be quite painless for you (and the end result will be a massive speed increase). This post should be considered a temporary solution that is “better” than downgrading to Composer 1. If you, like me, work on many projects, you definitely want to use Composer 2 on as many of them as possible.

Related Content