官网地址
Windows Installer
The installer will download composer for you and set up your PATH environment variable so you can simply call composer
from any directory.
Download and run Composer-Setup.exe - it will install the latest composer version whenever it is executed.
Command-line installation
Run this in your terminal to get the latest Composer version:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
This installer script will simply check some php.ini settings, warn you if they are set incorrectly, and then download the latest composer.phar in the current directory. The 4 lines above will, in order:
- Download the installer to the current directory
- Verify the installer SHA-384 which you can also cross-check here
- Run the installer
- Remove the installer
WARNING: Please do not redistribute the install code. It will change with every version of the installer. Instead, please link to this page or check how to install Composer programmatically.
Installer Options
--install-dir
You can install composer to a specific directory by using the --install-dir
option and providing a target directory. Options must be appended to --
so that PHP ignores them, like -- --install-dir=bin
, example:
php composer-setup.php --install-dir=bin
--filename
You can specify the filename (default: composer.phar) using the --filename
option. example:
php composer-setup.php --filename=composer
--version
You can install composer to a specific release by using the --version
option and providing a target release. example:
php composer-setup.php --version=1.0.0-alpha8
Preview / Snapshot Releases
By default the installer and composer self-update
will download stable versions only. If you would like to help test pre-release versions you can use the --preview
flag on either installer or self-update. For snapshot builds which are done from the latest Composer commit, you can use the --snapshot
flag.