I've adapted some command line below for make our life easier, so just copy and paste line by line and execute it interminal. If you want to view official installation guide let's see official installation guide.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
After everything install coorectly we'll make alias. In this case, I've using the zsh as my default terminal here is a command for adding an alias.
In case if you're using the default bash just change ~/.zshr
to vi ~/.bash_profile
.
vi ~/.zshrc
Put the line below on somewhere in file (that'll make us be able to call composer
on commandline)
alias composer="php /usr/local/bin/composer"
Reload current shell's environment with following command(or just close and re open the terminal).
source ~/.zshrc
If you're interested with zsh or new generation of terminal please see this link