Repository: iterative/dvc

Issue:
`DVC_SITE_CACHE_DIR` environment variable is ignored in Linux
# Bug Report


## Description

Setting the `DVC_SITE_CACHE_DIR` environment variable does not work to set the `core.cache_site_dir` directory in Linux (Unix), but it does in Macos.

### Reproduce

Setup repo:
```console
mkdir test_repo
cd test_repo
dvc init --no-scm
```

Failure under Linux:
```console
$ env DVC_SITE_CACHE_DIR=/tmp/use_this_dir/ dvc doctor
DVC version: 3.60.0 (conda)
---------------------------
Platform: Python 3.10.18 on Linux-6.2.0-1018-aws-x86_64-with-glibc2.35
Subprojects:
        dvc_data = 3.16.10
        dvc_objects = 5.1.1
        dvc_render = 1.0.2
        dvc_task = 0.40.2
        scmrepo = 3.3.11
Supports:
        gdrive (pydrive2 = 1.21.3),
        http (aiohttp = 3.9.5, aiohttp-retry = 2.9.1),
        https (aiohttp = 3.9.5, aiohttp-retry = 2.9.1),
        s3 (s3fs = 2025.5.1, boto3 = 1.37.3),
        ssh (sshfs = 2025.2.0)
Config:
        Global: /home/rgoya/.config/dvc
        System: /etc/xdg/dvc
Cache types: <https://error.dvc.org/no-dvc-cache>
Caches: local
Remotes: None
Workspace directory: nfs4 on <>
Repo: dvc (no_scm)
Repo.site_cache_dir: /var/tmp/dvc/repo/585c4d66c2c015b2711eaa0a231373fa
```
### Expected

Given `env DVC_SITE_CACHE_DIR=/tmp/use_this_dir/` the last line of the example above should have read:
```console
Repo.site_cache_dir: /tmp/use_this_dir/repo/585c4d66c2c015b2711eaa0a231373fa
```

This works well in MacOS:
```console
env DVC_SITE_CACHE_DIR=/tmp/use_this_dir/ dvc doctor
DVC version: 3.60.0 (conda)
---------------------------
Platform: Python 3.10.18 on macOS-15.5-x86_64-i386-64bit
Subprojects:
        dvc_data = 3.16.10
        dvc_objects = 5.1.1
        dvc_render = 1.0.2
        dvc_task = 0.40.2
        scmrepo = 3.3.11
Supports:
        gdrive (pydrive2 = 1.21.3),
        http (aiohttp = 3.9.5, aiohttp-retry = 2.9.1),
        https (aiohttp = 3.9.5, aiohttp-retry = 2.9.1),
        s3 (s3fs = 2025.5.1, boto3 = 1.37.3),
        ssh (sshfs = 2025.2.0)
Config:
        Global: /Users/rgoya/Library/Application Support/dvc
        System: /Library/Application Support/dvc
Cache types: <https://error.dvc.org/no-dvc-cache>
Caches: local
Remotes: None
Workspace directory: apfs on /dev/disk1s5s1
Repo: dvc (no_scm)
Repo.site_cache_dir: /tmp/use_this_dir/repo/a6958b543852ebf6e514f92df3ed1d64
```





Discussion:

Patch:
diff --git a/dvc/dirs.py b/dvc/dirs.py
index c6737678d6..881a30840a 100644
--- a/dvc/dirs.py
+++ b/dvc/dirs.py
@@ -24,6 +24,9 @@ def site_cache_dir():
     from platformdirs import PlatformDirs
     from platformdirs.unix import Unix
 
+    if dvc_site_cache_dir := os.getenv(env.DVC_SITE_CACHE_DIR):
+        return dvc_site_cache_dir
+
     if issubclass(Unix, PlatformDirs):
         # Return the cache directory shared by users, e.g. `/var/tmp/$appname`
         # NOTE: platformdirs>=5 changed `site_cache_dir` to return /var/cache/$appname.
@@ -34,6 +37,4 @@ def site_cache_dir():
         #        In the future, consider migrating to a more secure directory.
         return f"/var/tmp/{APPNAME}"  # noqa: S108
 
-    return os.getenv(env.DVC_SITE_CACHE_DIR) or platformdirs.site_cache_dir(
-        APPNAME, APPAUTHOR, opinion=True
-    )
+    return platformdirs.site_cache_dir(APPNAME, APPAUTHOR, opinion=True)


Test patch:
diff --git a/tests/unit/test_dirs.py b/tests/unit/test_dirs.py
index 0098c0cbf9..259a330af6 100644
--- a/tests/unit/test_dirs.py
+++ b/tests/unit/test_dirs.py
@@ -3,7 +3,7 @@
 import pytest
 
 from dvc.dirs import global_config_dir, site_cache_dir
-from dvc.env import DVC_GLOBAL_CONFIG_DIR
+from dvc.env import DVC_GLOBAL_CONFIG_DIR, DVC_SITE_CACHE_DIR
 
 
 def test_global_config_dir_respects_env_var(monkeypatch):
@@ -13,5 +13,11 @@ def test_global_config_dir_respects_env_var(monkeypatch):
 
 
 @pytest.mark.skipif(sys.platform != "linux", reason="Only for Unix platforms")
-def test_site_cache_dir_on_unix():
+def test_site_cache_dir_on_unix(monkeypatch):
+    monkeypatch.delenv(DVC_SITE_CACHE_DIR, raising=False)
     assert site_cache_dir() == "/var/tmp/dvc"
+
+
+def test_site_cache_dir_env_var(monkeypatch):
+    monkeypatch.setenv(DVC_SITE_CACHE_DIR, "foo_bar")
+    assert site_cache_dir() == "foo_bar"