How to clear the Composer cache?
Run composer clear-cache or composer clearcache to safely and effectively clear the Composer cache, which removes cached packages and metadata and resets the internal cache. 2. Alternatively, manually delete the cache directory by first checking its location with composer config cache-dir, then using system commands like rm -rf ~/.composer/cache on Linux/macOS or rmdir /s %APPDATA%\Composer\cache on Windows Command Prompt, or Remove-Item -Recurse $env:APPDATA\Composer\cache in PowerShell. 3. Clear the cache when encountering issues like outdated packages, installation failures, corrupted downloads, or after switching PHP versions, as it forces Composer to re-download packages and re-evaluate dependencies. 4. Note that clearing the cache does not affect composer.json or vendor files, Composer automatically rebuilds the cache on next use, and using composer update --no-cache allows one-time operations without global cache clearing. Running composer clear-cache is a simple, safe, and effective solution for most cache-related issues.
Clearing the Composer cache can help resolve issues with outdated package versions, corrupted downloads, or slow performance. Here's how to do it properly.

Use the Built-in Clear Cache Command
Composer provides a dedicated command to clear its cache. Run:
composer clear-cache
or

composer clearcache
Both commands do the same thing. This will:
- Delete all cached packages and metadata
- Reset the internal cache used by Composer
- Display a confirmation of what was cleared
This is the safest and recommended method.

Alternative: Manually Delete the Cache Directory
If the command doesn't work or you want more control, you can manually remove the cache folder.
First, check where Composer stores the cache:
composer config cache-dir
Then delete it using your system's file tools. On most systems:
Linux/macOS:
rm -rf ~/.composer/cache
Windows (Command Prompt):
rmdir /s %APPDATA%\Composer\cache
Windows (PowerShell):
Remove-Item -Recurse $env:APPDATA\Composer\cache
Note: The global Composer directory is usually %APPDATA%\Composer
on Windows, ~/.composer
on macOS/Linux.
When Should You Clear the Cache?
Common scenarios include:
- You're not getting the latest version of a package
- Composer fails to install or update with network errors
- You suspect a corrupted package download
- Switching between different versions of PHP or platforms
Clearing the cache forces Composer to re-download packages and re-evaluate dependencies.
Pro Tips
- Clearing the cache doesn't affect your
composer.json
or installed vendor files - Composer will rebuild the cache automatically on next use
- If you're on a slow connection, expect slightly longer wait times after clearing
- You can also use
composer update --no-cache
for one-off operations without clearing globally
Basically, just run composer clear-cache
and you’re good. It’s simple, safe, and effective.
The above is the detailed content of How to clear the Composer cache?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When using Composer in a production environment, you need to pay attention to safety, stability and performance. 1. Use composerinstall-no-dev to reduce unnecessary development dependencies and reduce online environment risks; 2. Always submit and rely on composer.lock files to ensure version consistency, and avoid using updates during deployment; 3. Optional configuration platform-check=false ignores platform differences warnings, which is suitable for building packaging scenarios; 4. Enable APCU to accelerate automatic loading to improve performance, especially suitable for high concurrency services, while paying attention to namespace uniqueness to avoid cache conflicts.

Installing Composer takes only a few steps and is suitable for Windows, macOS, and Linux. Windows users should download Composer-Setup.exe and run it to ensure that PHP is installed or XAMPP is used; macOS users need to execute download, verification, and global installation commands through the terminal; Linux users operate similarly to macOS, and then use the corresponding package manager to install PHP and download and move the Composer file to the global directory.

Tomaintainapplicationsecurity,keepdependenciesupdatedusingautomatedtoolslikeDependabot,Renovate,orSnyktotrackandapplyupdates.1)UsethesetoolstoautomatedependencychecksandintegratewithCI/CDpipelinesforreal-timealertsandmergerestrictions.2)Regularlyscan

To check whether Composer is installed correctly, first run the composer--version command to view the version information. If the version number is displayed, it means that it is installed. Secondly, use the composerdiagnose command to detect configuration problems and ensure that the environment variables and permissions are normal. Finally, try to verify the functional integrity through the composerrequiremonolog/monolog installation package. If the vendor directory is successfully created and the dependency is downloaded, it means that Composer is fully available. If the above steps fail, you may need to check whether PHP has been installed globally or adjusted system path settings.

To install the Composer plug-in, please first confirm that Composer is installed and the composer.json file exists, and then follow the following steps: 1. Make sure that Composer has been installed and created composer.json; 2. Search and copy the required plug-in name on Packagist; 3. Use the composerrequirequire command to install the plug-in, such as composerrequiredealerdirect/phpcodesniffer-composer-installer; 4. Verify whether the plug-in is effective and check compatibility and configuration. Follow these steps to correctly install the Composer plug-in.

You can make Composer use a specific PHP version by specifying PHP binary files, using version management tools, or configuring composer.json. 1. In Unix-like systems, you can set an alias or export the COMPOSER_PHP environment variable to directly specify the PHP binary file; 2. Use tools such as phpenv or brew to switch the PHP version to achieve global or project-level version control; 3. Configure the platform.php field in composer.json to declare the PHP version required for the project to ensure that the dependency check is correct; 4. Windows users can call the specified PHP version by modifying the PATH environment variable or creating a batch script to call the specified PHP version.

Stabilityflagslike@dev,@alpha,@beta,and@stableindicatesoftwarematurity.1)@devmeansearlydevelopmentwithpossiblebreakingchanges.2)@alphaisanunstableearlytestingphase.3)@betaindicatesimprovedfunctionalitybutwithpotentialbugs.4)@stablemeansproduction-rea

To add a custom repository to the Composer configuration, edit the composer.json file in the project and specify the repository information under the "repositories" key. The specific steps are as follows: 1. Determine the repository type, such as VCS (Git, SVN, etc.), Composer, PEAR or Package; 2. Add the "repositories" block in composer.json and fill in the repository type and URL. For example, when using a VCS-type Git repository, the format is {"type":"vcs","url":"https
