Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Composer warns it is proceeding without cache

ErrorCannot create cache directory /home/deploy/.cache/composer/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache.

Short answer

Composer tried to create its cache folder, or write to it, and could not, so it runs without a cache. The path comes from COMPOSER_CACHE_DIR or from the Composer home folder. Point COMPOSER_CACHE_DIR at a folder your user can write, or set cache-read-only if the disk is read-only.

  • Applies to Composer 2.8, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the path in the warning, then see who owns it and whether your user may write to it.

    ls -ld ~/.cache/composer ~/.composer 2>&1; id -un
  2. 2Match what you see, then jump to its fix

    1. 1The folder exists, but ls shows an owner that is not you (often root).The cache folder belongs to another user or is not writableFix
    2. 2The path is inside a read-only layer, and touching a file there fails with Read-only file system.The filesystem is read-only (container, CI or locked-down host)Fix
    3. 3A one-off script or image build where the cache is never reused.You do not want a cache at all in this runFix

What does the error look like?

  • Cannot create cache directory /home/deploy/.cache/composer/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache.
  • See also cache-read-only config if your filesystem is read-only.

Cause 1 of 3

The cache folder belongs to another user or is not writable

1Check

Composer disables the cache when mkdir fails or when the folder is not writable for the current user.

ls -ld ~/.cache/composer; id -un

2Fix

Use a cache folder your user owns for this run, or give the folder back to your user.

export COMPOSER_CACHE_DIR="$HOME/.composer-cache"
composer install

3Verify

Run Composer again; the warning is gone and the folder fills up.

composer install && ls "$COMPOSER_CACHE_DIR"

Confirmed by getcomposer.org

Did this fix it?

Cause 2 of 3

The filesystem is read-only (container, CI or locked-down host)

1Check

The warning itself names the cause: it points to the cache-read-only setting for read-only filesystems.

touch ~/.cache/composer/.t && echo writable

2Fix

Point the cache at a writable temporary folder, or, for an existing cache you only want to read, turn on the documented cache-read-only config option.

export COMPOSER_CACHE_DIR=/tmp/composer-cache
composer install

3Verify

Run the install again and confirm the warning no longer appears.

composer install --no-interaction

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 3

You do not want a cache at all in this run

1Check

The --no-cache option disables the cache folder, the same as setting COMPOSER_CACHE_DIR to /dev/null.

composer --version

2Fix

Pass --no-cache so Composer does not look for the folder.

composer install --no-cache

3Verify

The install finishes without the warning.

composer install --no-cache --no-interaction

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Do not mix sudo and normal Composer runs in the same project: stick to one user.
  • In CI, set COMPOSER_CACHE_DIR to a folder the job owns and cache that folder between runs.
  • Use composer clear-cache if an old cache is damaged, rather than deleting folders by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.