Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuring cache dir #2181

Open
unional opened this issue Dec 7, 2016 · 10 comments
Open

configuring cache dir #2181

unional opened this issue Dec 7, 2016 · 10 comments

Comments

@unional
Copy link

unional commented Dec 7, 2016

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
yarn currently save cached packages in a default directory: /Users/<user>/Library/Caches/yarn or C:/Users/<user>/AppData/Local/Yarn/cache.

When a lot of packages are cached, each user on the system to consume a lot of space on the primary drive.

I would like to config yarn to save cache packages in a backup drive which has a lot more space, and may cache packages from all users in the same location (as discussed in #2125)

What is the expected behavior?
yarn config set cache-dir <location>

Please mention your node.js, yarn and operating system version.
yarn: 0.17.6

@unional
Copy link
Author

unional commented Dec 7, 2016

I notice there is a yarn --cache-folder <path> to specify a custom cache folder for the particular project. But this is different as I'm suggestion to make the default location configurable.

By the way, --cache-folder and yarn cache dir is not consistent in term of wording: folder vs dir

@willxy
Copy link

willxy commented Mar 4, 2017

Running into this myself just now, yarn config set cache-folder <location> seems to effectively set the cache dir default.

@Couto
Copy link

Couto commented May 12, 2017

Slightly related but is it possible to configure the cache dir as a command flag during the installation process?

e.g.: yarn install --cache-folder=/opt/project/.local-yarn-cache

This is useful in some CI environments where you can't write outside of the project's folder.


After some investigation, I've noticed that --cache-folder is the correct flag, but since Yarn still tries to write the .config folder outside of the project directory, it will always fail in my use cases.

@wakeful
Copy link

wakeful commented Jun 2, 2017

@Couto you can work around .config location by simply overwriting the $HOME env variable before running yarn

e.g.: HOME=$(pwd) yarn install

@chapterjason
Copy link

Using

--cache-folder "<path>"
--cache-dir "<path>"
--cache "<path>"
cache-folder "<path>"
cache-dir "<path>"
cache "<path>"

None of them work.

Also https://yarnpkg.com/lang/en/docs/cli/cache/#toc-change-the-cache-path-for-yarn does not work.

Same goes for global folder but --global-folder is working under 1.13.0

@hugmanrique
Copy link

hugmanrique commented Nov 29, 2019

wakeful's solution didn't work inside a node:current-alpine Docker image for some reason. Instead of overriding the HOME env var, we did the following:

yarn config set cache-folder $(pwd)/.yarn-cache

This will set an absolute path in a global config, but it should be fine for CI configs (our use case).

@slykar
Copy link

slykar commented Mar 3, 2020

The absolute path seems to do the job of actually setting this config value to what you might want to use.

root@9ad1edf1833c:/home# yarn config set cache-folder .my-cache
root@9ad1edf1833c:/home# yarn cache dir
/usr/local/share/.my-cache/v6

root@9ad1edf1833c:/home# yarn config set cache-folder $(pwd)/.my-cache
root@9ad1edf1833c:/home# yarn cache dir
/home/.my-cache/v6

@zoidyzoidzoid
Copy link

We use the YARN_CACHE_DIR env var and it seems to work, though you'd expect that to be the same as --cache-dir.

@mpdude
Copy link

mpdude commented May 31, 2021

Is that really YARN_CACHE_DIR, or rather YARN_CACHE_FOLDER?

@phil-lgr
Copy link

Should be YARN_CACHE_FOLDER according to the docs: https://classic.yarnpkg.com/en/docs/cli/cache/#toc-change-the-cache-path-for-yarn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants