phpcomposer-phpmultiple-versions

keep composer 1 & 2 both in same machine


How we can use composer 1 & composer 2 both in the same machine. As a developer we worked on the multiple project in the same machine and situation comes where project 1 required composer 1 and project 2 required compower version 2.


Solution

  • This is what I used to have composer 1 & 2 both in the same machine. I am hoping this will helpful for someone, who want to use composer 1 & 2 both as separate command

    Keep Composer 1 & 2 as separate command

    Setup Composer 1:

    1. Copy the current composer directory to new

      cp `which composer` /usr/local/bin/composer1
      
    2. Update it to version 1:

      composer1 self-update --1
      

    Upgrade to Composer 2 & create alias:

    1. Update composer to version 2

      composer self-update --2
      
    2. Create symlink for composer2 (optional)

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

    Now you can use composer or composer2 command for the project dependent on composer 2 and composer1 command for the project have dependency on composer 1.

    Note: you might required to use sudo before the command