有没有办法在 Windows 上全局安装 Composer?

2022-01-21 00:00:00 windows php composer-php

我已阅读 Composer 的全局安装文档,但它仅适用于 *nix 系统:

I've read the global installation documentation for Composer, but it's for *nix systems only:

curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

我会很高兴在 Windows 上做同样的事情,那是我开发机器的操作系统.我可以跑

I would be such happy doing the same on Windows, that's the OS of my development machine. I would be able to run

composer update

来自 composer.json 所在的任意文件夹.解释器 php.exe 已经在 PATH 变量中.

From an arbitrary folder where composer.json exists. Interpreter php.exe is already in PATH variable.

有什么线索吗?

推荐答案

当然.只需将 composer.phar 放在 C:phpcomposer.phar 之类的地方,然后在 PATH 中的某个地方创建一个名为 composer.bat 的批处理文件,该文件执行以下操作:

Sure. Just put composer.phar somewhere like C:phpcomposer.phar, then make a batch file somewhere within the PATH called composer.bat which does the following:

@ECHO OFF
php "%~dp0composer.phar" %*

%*"重复传递给 shell 脚本的所有参数.

The "%*" repeats all of the arguments passed to the shell script.

然后你就可以到处乱跑composer update了!

Then you can run around doing composer update all ya want!

相关文章