若要在当前目录中快速安装 Composer,请在终端中运行以下脚本:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
ShellScript这个安装程序脚本将简单地检查一些设置, 如果设置不正确,请警告您,然后 下载当前目录中的最新版本。
上面的 4 行将按顺序排列:php.ini
composer.phar
- 将安装程序下载到当前目录
- 验证安装程序 SHA-384,您也可以在此处进行交叉检查
- 运行安装程序
- 删除安装程序
最有可能的是,您希望将 放入 PATH 上的目录中,以便您可以简单地从任何目录(全局安装)调用,例如:composer.phar
composer
sudo mv composer.phar /usr/local/bin/composer
ShellScript测试:
composer -V
composer self-update
ShellScript输出如下:
Composer version 2.7.4 2024-04-22 21:17:03
PHP version 8.3.6 (/usr/local/php/bin/php)
Run the "diagnose" command to get more detailed diagnostics output.
You are already using the latest available Composer version 2.7.4 (stable channel).
ShellScript
发表回复