Step 1. Install Composer
Download composer binary file from getcomposer.org website by running the following command. It will create a composer.phar file in the current directory.
curl -sS https://getcomposer.org/installer | php
Now, copy this composer.phar file under bin directory to make available anywhere in the system. Also, set the execute permission on file. I have changed the filename from composer.phar to composer for the easy use.
sudo mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
Run composer command on the command prompt. This will provide you composer version details along with options available with composer command.
Upgrade PHP Composer
The PHP composer provides a command-line option (self-update) to upgrade itself. You can simply run below command from the terminal to upgrade compose on your macOS.
sudo composer self-update
more step: https://wpbeaches.com/set-up-composer-and-phpcodesniffer-on-visual-studio-code-on-macos/