先安裝 php-cli ( PHP command line )
sudo apt install php-cli
下載 Composer 安裝檔
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
驗證下載檔,https://composer.github.io/pubkeys.html 中取得 驗證碼,並帶入指令中,如果回覆Installer verified代表下載檔可以正常安裝
php -r "if (hash_file('sha384', 'composer-setup.php') === '驗證碼') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
安裝 composer
php composer-setup.php
移除安裝檔
php -r "unlink('composer-setup.php');"
將執行檔搬移到執行檔目錄
sudo mv composer.phar /usr/local/bin/composer
安裝完成囉
#composer -V
Composer version 2.3.5 2022-04-13 16:43:00