在与当前目录不同的目录中运行编写器

我不知道是否有人问过这个问题,因为搜索结果主要是关于移动库安装目录的。

我有一个全球安装的作曲家命令。有没有一种方法可以运行,例如,composer install在一个不同的目录比当前,即指定的目录,我希望你运行的命令?

例如,在 /home/someuser中,我希望获得与在 /home/someuser/myproject中运行 composer install相同的结果。当然,一种方法是简单地改变工作目录,播放作曲家的作品,然后回去。

75373 次浏览

Try composer install -h. There you'll find an option --working-dir (or -d). And that's what you're looking for.

Then run:

composer install --working-dir=/home/someuser/myproject

You can find more in composer docs.


Depending on your operating system, the = might need to be removed:

composer install --working-dir /home/someuser/myproject

In addition to the above answer from Tomáš Votruba i had to append the = charachter on OSX. So the full command would be:

composer install -d=/home/someuser/myproject

My first post on SO so was unable to simply add this as a comment.

Run:

cd /home/mysites/google.com

Then run:

composer require facebook/graph-sdk

Above steps will open up the directory named (google.com) and install facebook Graph SDK there.

This works for me, PHP 7.3 on ubuntu 18.04

Install

composer install --working-dir=/your_composer_dir

Update

composer update --working-dir=/your_composer_dir

I tried what others said, but it was giving me: Invalid working directory specified 'PATH' does not exist. Although it was my working dir that contained composer.json!

I don't know why anyway, but this worked for me (only for gnu/linux users):

composer --working-dir=$(pwd)

And by the way, if you had run composer -h, it would've told you the solution:

-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.