When building certain code with bazel I'm running out of storage space. I'd like bazel to store its things on a USB drive instead of in my ~/.cache
folder. How can I tell bazel to do this?
Asked
Active
Viewed 1.0k times
13

Matt Kleinsmith
- 1,017
- 3
- 13
- 24
3 Answers
18
Use the --output_user_root
flag.
Example:
bazel --output_user_root=/path/to/directory build //foo:bar
-
1When trying this solution on an AWS instance, I met the warning like WARNING: Output base '/workspace/bazel/.cache/0d1ff2dcdcd5fe715305037694b909f9' is on NFS. This may lead to surprising failures and undetermined behavior. – Leo5188 May 28 '19 at 20:16
-
eh, the link now returns 404 page not found :( – Smankusors Aug 04 '20 at 20:44
5
You can change the outputRoot directory by changing the $TEST_TMPDIR
variable.
export TEST_TMPDIR=/path/to/directory
From the bazel docs:
The outputRoot directory is
~/.cache/bazel
. (Unless $TEST_TMPDIR is set, as in a test of bazel itself, in which case this directory is used instead.)

Matt Kleinsmith
- 1,017
- 3
- 13
- 24
-
4Setting TEST_TMPDIR makes Bazel believe it's running inside of a test and will heavily limit its resource use, slowing down builds. – László Apr 18 '19 at 05:42
-
2
I symlinked ~/.cache/bazel
to a directory on my other drive. Looks to be working so far. i.e.
ln -s /mnt/otherdrive/bazel_cache ~/.cache/bazel
I thought to move the old cache to avoid rebuilding, but I noticed symlinks to directories within the cache and didn't want to deal with transferring those so they pointed to the new directory as well. So I just deleted the old cache, symlinked, and rebuilt.

crizCraig
- 8,487
- 6
- 54
- 53