107

I ran into a problem using composer for installing/uninstalling some dependencies in laravel, which come back after deleting them from composer.json and deleting their vendor folder.

I initially used dflydev's markdown package, but now I want to change it to michelf's php-markdown, but I can't uninstall the old one since it comes back loaded from cache. I checked at AppData\Roaming\Composer and it is empty.

Any clue as to why this is happening?

  - Installing dflydev/markdown (dev-master dee1f7a)
    Loading from cache
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
Tarik
  • 2,151
  • 4
  • 19
  • 26
  • Have you tried anything to resolve this problem? If yes, please share your attempts – Nico Haase Apr 24 '20 at 08:58
  • I tried adding --no-cache option to my composer command and it downloaded the dependencies without loading them from cache.... – T.melz Oct 29 '20 at 19:56

9 Answers9

194

You can use the following command to clear the cache irrespective of the OS you are on:

php composer.phar clear-cache

or if composer is installed globally

composer clear-cache
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
Atish Goswami
  • 2,155
  • 1
  • 11
  • 9
50

I think, you can run your composer commands with --no-cache option flag like

composer install --no-cache

Or

composer require <package-name> --no-cache

Or

composer update [<package-name>] --no-cache
20

If you want to clear all packages cache, please try following:

$ composer clearcache

Or to just clear one or a few packages:

$ composer clearcache packagename1 packagename2 ...

You can also use clear-cache which is an alias for clearcache.

Source : https://blog.liplex.de/clear-composer-cache/

monsur.hoq
  • 1,135
  • 16
  • 25
  • 4
    It's not possible anymore to clear cache for specific packages. There is a comment in the post you've referenced and the post itself was updated. – geiger Jul 13 '18 at 19:44
  • Please add some further explanation to your answer. How does clearing the cache of downloaded files help to install or not install any pacakge? – Nico Haase Apr 24 '20 at 08:58
18

composer caches packages under vendor/packagename convention. So you shouldn't run into any issue, just because the packagename is used in another vendor's package.

the cache locations are:

  • Windows: %LOCALAPPDATA%\Composer\files\vendor\packagename
  • Linux: ~/.composer/cache/files/vendor/packagename
  • macOS: ~/Library/Caches/composer/files/packagename
Boschman
  • 825
  • 1
  • 10
  • 17
Simon Wicki
  • 4,029
  • 4
  • 22
  • 25
  • under windows its %LOCALAPPDATA%\Roaming\Composer and its as i said empty, and the package in question isn't used in any dependency as a i just installed it recently. – Tarik Mar 27 '14 at 23:13
  • Please add some further explanation to your answer. How does clearing the cache of downloaded files help to install or not install any pacakge? – Nico Haase Apr 24 '20 at 08:59
  • 1
    UPDATE 2022: for OSX: ~/Library/Caches/composer/ – Nikolay Shabak Jan 07 '22 at 15:14
  • This will work on any platform and give you the exact location: `composer config cache-dir` – datashaman May 19 '22 at 11:18
10

Don't edit your composer.json file manually to remove a package - it will remain in composer.lock.

Use composer remove to delete the old package then composer require to install the replacement.

Darvanen
  • 626
  • 1
  • 9
  • 19
  • 1
    This looks like the first attempt to really solve the problem - thanks for your answer! – Nico Haase Apr 24 '20 at 09:00
  • 1
    Yeah... We should probably change the question title, it's a bit misleading – Darvanen Apr 25 '20 at 10:23
  • This doesn't work if the package has been installed via dependency. There are reasons why you might need to manually edit composer.json ie if you want to update a reference to use a local path for a package. – Matt Clegg May 01 '20 at 08:17
  • > This doesn't work if the package has been installed via dependency. Correct. But the OP states directly that they are deleting the items from `composer.json` and they are magically returning > There are reasons why you might need to manually edit composer.json Absolutely. Again, not applicable in this context, where the OP is trying to remove a whole package. I *could* have said "run `composer update` after deleting the value" but that comes with *so* much more required knowledge. – Darvanen May 05 '20 at 01:24
7

In some cases (for example OpenSuse 42.1) all user cache are puts in:

~/.cache/

For the composer, the same as other applications, the cache path is:

~/.cache/composer/

So, just remove this folder as follow:

rm -fR ~/.cache/composer
Mostafa Barmshory
  • 1,849
  • 24
  • 39
  • Please add some further explanation to your answer. How does clearing the cache of downloaded files help to install or not install any pacakge? – Nico Haase Apr 24 '20 at 08:59
3

run the following command

rm -rf ~/.composer/cache*

if Permission denied add sudo

Sir Mbuki
  • 1,200
  • 8
  • 7
  • 2
    If some one is having permissions issues in their own home directory, "add sudo" to a `rm -rf` command that includes a wildcard is not a good idea. – Thoughtful Dragon Apr 22 '20 at 16:07
  • Please add some further explanation to your answer. How does clearing the cache of downloaded files help to install or not install any pacakge? – Nico Haase Apr 24 '20 at 08:59
2

On Window, I see the composer cache file located in
C:\Users\{your_user}\AppData\Local\Composer\files

enter image description here

It stores ZIP files. The below image has 2 Zip files because I have downloaded 2 versions of monolog (1.0.1 and 1.0.2) enter image description here

To remove the cache, simply delete the Zip file or folder.

Linh
  • 57,942
  • 23
  • 262
  • 279
-1

So the only thing that worked for me on my Macbook was removing the package from my composer.json, deleting my composer.lock, running composer update, then adding the package back to composer.json, deleting my composer.lock(again), and running composer update (again). I had a local package in my instance of Laravel Nova that I changed to all lowercase from CamelCase and no matter what I did, it kept adding the package with the old CamelCase name. Didn't matter if I cleared caches or anything.

samnau
  • 683
  • 7
  • 7