php – How to change Composer's default installation folder?


Is there any way to change where Composer installs dependencies?

Composer always installs in the vendor folder, but could you change it to another folder?


Inside the project's composer.json set the config -> vendor-dir , example:

"config": {
    "vendor-dir": "system/vendor"

In my case I used system/vendor

PS: I believe that for global packages you can set the environment variable COMPOSER_VENDOR_DIR :

Note that it is possible to change the vendor via command line using:

composer require pacote

On Windows:

set COMPOSER_VENDOR_DIR=outro_diretorio
composer require pacote

Remembering that this only changes at runtime and if there are other packages they will be installed again in the new directory, so I don't see many advantages in using for use, the use of the COMPOSER_VENDOR_DIR variable would be more interesting if the vendor was controlled by another environment or program , to generate the name or location as some rule was needed to describe it.

A hypothetical example would be if you created a project generator (in CLI maybe) based on a "template" project on your machine, then the installed packages should always go to that template and your "CLI" would always copy from the template at the time to send to production, but for development all projects would base the template, it would be one of many likely ideas that this could be useful, where another program/environment would control composer with COMPOSER_VENDOR_DIR .

Scroll to Top