Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change composer global path (Windows)

Composer uses %APPDATA%\Composer directory by default for global packages.
So I need to add %APPDATA%\Composer\vendor\bin path to my user PATH environment variable.

Can I change installation directory to something like C:\php\composer? How can I do it?

like image 553
Dmitry Avatar asked Aug 28 '14 12:08

Dmitry


People also ask

How do I install Composer globally in Windows?

Step 1: Navigate to the official composer website. Step 2: Then click on the Download button. Step 3: Then click on the Composer-Setup.exe & download the file. Step 4: Then click on “Install for all users”.


3 Answers

On Windows, when global install of a library / package is done, composer stores the package in a Composer directory inside windows **application data folders** which by default is C:\Users{user name}\AppData\Roaming`.

To change this folder to say C:\php\composer, create a COMPOSER_HOME environmental variable with the value set to C:\php\composer.

The steps below explain how environmental variables are added in Windows. * Press Windows Key + Pause Break then click Advanced system Settings

Windows system settings
(source: w3guy.com)

Click the Environmental variables button.

Environmental variable button
(source: w3guy.com)

Under System variables, click New... button and add the environmental variable like so:

Add environmental variables in Windows
(source: w3guy.com)

You might want to restart your PC for this to take effect.

Credit: http://w3guy.com/change-composer-global-package-install-folder-windows/

like image 68
Collizo4sky Avatar answered Sep 22 '22 06:09

Collizo4sky


I found an answer in the source code: https://github.com/composer/composer/blob/master/src/Composer/Factory.php#L45

So environment variable COMPOSER_HOME must be defined as C:\php\composer.

like image 32
Dmitry Avatar answered Sep 22 '22 06:09

Dmitry


Go to folder

(C:\Users(your user)\AppData\Roaming\Composer )

Then create new folder (vendor)

and

in vendor create (bin) and copy (C:\composer\composer.phar) to (bin) .

like image 43
user2964793 Avatar answered Sep 26 '22 06:09

user2964793