Change composer global path (Windows)

Change composer global path (Windows)

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Change Composer global path (Windows)

Composer defaults to storing globally installed packages in %APPDATA%\Composer on Windows. While this location is standard and generally safe, it often places the executable binaries deep within your user profile directory. Consequently, you frequently need to manually add %APPDATA%\Composer\vendor\bin to your system PATH environment variable to access tools like phpunit, pest, or custom CLI scripts.

If your workflow relies heavily on command-line tools and adding a nested path feels cluttered or prone to breaking during profile resets, you can change the installation directory entirely. You might prefer installing Composer binaries directly into a dedicated folder like C:\php\composer so they sit alongside other development utilities rather than scattered under your user settings.

Modifying the Installation Directory

To move Composer's global storage location, you must edit the configuration file before installing any new packages or running update commands. This ensures that subsequent installations respect your custom directory structure.

Create or edit the composer.json file in a temporary location (or simply run the command directly) using the --config flag to specify a local configuration override for this session, or better yet, modify the global config file located at %APPDATA%\Composer\config.json. However, since you haven't installed Composer globally yet (or want to reset), the most direct approach is setting the environment variable COMPOSER_HOME before running any installation command.

Run the following command in your terminal or Command Prompt:

set COMPOSER_HOME=C:\php\composer
call composer config --global repositories.vendors.installs.path C:\php\composer

Wait, that approach mixes environment variables with Composer's internal config keys incorrectly. Let's refine this. The COMPOSER_HOME environment variable is the recognized standard for overriding the default cache and vendor directories globally without touching every config file manually.

By setting COMPOSER_HOME=C:\php\composer, Composer will automatically look for its cache, plugins, and the global dependencies in that new root. When you subsequently run composer global require vendor/package, the executable binaries for those packages will be dropped into C:\php\composer\vendor\bin.

Updating Your Environment Variables

Once you have set COMPOSER_HOME to your desired directory, the next step is ensuring the system can find those binaries. You must still add the bin subdirectory of your new home to the PATH variable.

Navigate to System Properties > Environment Variables. Under User variables, select Path and click Edit. Add a new entry pointing to:

C:\php\composer\vendor\bin

Alternatively, if you prefer keeping the configuration within the COMPOSER_HOME directory structure but just changing the root, ensure that your application's shell (like VS Code or Git Bash) sources the updated environment. If you are using PowerShell, you might need to update your $PROFILE to persist the change:

$env:COMPOSER_HOME = "C:\php\composer"
$env:PATH = "$env:COMPOSER_HOME\vendor\bin;$env:PATH"

The config.json Approach

If you prefer not to rely on environment variables, you can explicitly define the home directory in the global configuration file. Open %APPDATA%\Composer\config.json and add or modify the home key:

{
    "home": "C:/php/composer"
}

Note that if this file does not exist yet, you can create it manually. However, be aware that Composer often generates this file automatically once you run a global command. If you set the COMPOSER_HOME environment variable first, Composer will use that path to generate or locate the config file correctly.

Trade-offs and Considerations

Moving Composer away from %APPDATA% offers better organization but introduces specific constraints. The primary consideration is consistency across different shells. On Windows, if you switch between Command Prompt, PowerShell, and WSL2, environment variable handling can vary slightly. Setting COMPOSER_HOME explicitly in every shell session ensures the path is always correct regardless of the underlying engine.

Another pitfall is clearing old global packages. If you previously installed tools to %APPDATA%\Composer\vendor, simply changing the config won't remove those files; they will remain orphaned until you manually delete them or move the old directory to a backup location. Always ensure you have access to your previous binaries if you intend to migrate data, though usually, it is cleaner to start fresh with the new path.

For developers managing complex environments where multiple PHP versions or Composer installations coexist, defining a dedicated root like C:\php\composer prevents namespace collisions and keeps the development environment tidy. This approach aligns well with practices advocated by modern Laravel deployment guides, such as those found at https://laravelcompany.com, which emphasize structured directory layouts for maintainability.

Our network