Composer version 2 will be mostly compatible with your existing workflows, while bringing some more great new features. You can find a more indepth description of what is new on the Get Composer site.
We will be upgrading from Composer version 1.10.1 to version 2 with the help of Home Brew for OSX.
First to get rid of the old version of composer so there are no conflicts in the future. Warning, if you are working with any projects that relied on the old version of composer, you can rename it. How to run two versions will be discussed later.
1. Find composer and remove or rename it.
which composer
composer is /Users/youruser/bin/composer
Now remove composer;
rm -r ~/bin/composer
which composer
-bash: type: composer: not found
Renaming option;
mv ~/bin/composer ~/bin/composer.old
Now, remember to either rename or remove the .composer folder from your home directory. You will need the -f flag to accomplish this because the folder has read only permission (0444).
rm -rf .composer
2. Update homebrew to the latest version.
brew upgrade
3. Install Composer.
brew install composer
==> Downloading https://getcomposer.org/download/2.0.8/composer.phar
######################################################################## 100.0%
🍺 /usr/local/Cellar/composer/2.0.8: 3 files, 2.1MB, built in 6 seconds
composer
-bash: /Users/youruser/bin/composer: No such file or directory
Oh, oh!! It doesn't work!
3.1 bash_profile work around.
Edit your profile to point to the new installation. The most common file this information will be kept in is the .bash_profile
open -e ~/.bash_profile
This opens .bash_profile in TextEdit. Use the search command to find composer amongst the text. The lines you are looking for should look like;
export PATH="$PATH:/usr/local/bin/"
export PATH="~/.composer/vendor/bin:/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:/Users/youruser/bin:$PATH"
Brew installs everything into /usr/local/Cellar. That makes instalations easy to find. You will look for the bin directory where the executable will be stored.
ls -al /usr/local/Cellar/composer/2.0.8
drwxr-xr-x 5 youruser admin 160 17 Dec 20:05 .
drwxr-xr-x 3 youruser admin 96 17 Dec 20:05 ..
drwxr-xr-x 3 youruser admin 96 17 Dec 20:05 .brew
-rw-r--r-- 1 youruser admin 712 17 Dec 20:05 INSTALL_RECEIPT.json
drwxr-xr-x 3 youruser admin 96 17 Dec 20:05 bin
Copy and paste the installation directory onto the end. It should look like this when finished;
export PATH="$PATH:/usr/local/bin/"
export PATH="~/.composer/vendor/bin:/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:/Users/youruser/bin:$PATH:/usr/local/Cellar/composer/2.0.8/bin"
Save the file and rehash your bash session. (Note, if the save fails then there will be a permissions issue. Change the permissions on the file than save again.)
exec bash
Verify the link works;
composer -V
Composer version 2.0.8
If there are errors, take note of the error output and fix problems accordingly.
3.2 Symlink work around.
Symlinks are easier to work with if the command lines exist in the bash_profile already. Using the steps from 3.1 to find the bin directory of the composer installation we can easily create a symlink to the ~/bin directory.
ln -s /usr/local/Cellar/composer/2.0.8/bin/composer /Users/youruser/bin/composer
Verify the link works;
composer -V
Composer version 2.0.8
Now, this is going to be a real pain in the butt everytime you upgrade Composer through HomeBrew. You will have to redo the work arounds everytime.
As for running two different versions, you would run the command either composer, or composer.old. It is that simple.
Hope this helps someone stream line the whole process!