uv Cheatsheet — Configuration & Cache
Configuration Hierarchy
uv reads configuration from (highest to lowest priority):
- CLI flags — e.g.,
--index-url - Environment variables — e.g.,
UV_INDEX_URL - Project-level —
uv.tomlorpyproject.toml[tool.uv]in the project directory (or nearest parent) - User-level —
~/.config/uv/uv.toml - System-level —
/etc/uv/uv.toml
If both uv.toml and pyproject.toml exist in the same directory, uv.toml wins and the [tool.uv] section in pyproject.toml is ignored.
pyproject.toml Configuration
All uv-specific settings go under [tool.uv]:
[tool.uv]
# Use a custom index
index-url = "https://my-private-registry.com/simple"
# Extra indexes
extra-index-url = ["https://pypi.org/simple"]
# Always exclude certain transitive deps
exclude-dependencies = ["werkzeug"]
# Force version constraints on transitive deps
constraint-dependencies = ["grpcio<1.65"]
# Override dep versions regardless of what's requested
override-dependencies = ["numpy==1.26.4"]
# Dependency groups to install by default
default-groups = ["dev"]
# Disable build isolation for specific packages
no-build-isolation-package = ["cchardet"]
# Default version specifier style when running uv add
default-version-specifier = ">="Standalone uv.toml
Same structure, but without the [tool.uv] prefix:
# ~/.config/uv/uv.toml (user-level)
index-url = "https://my-company-registry.com/simple"Custom Package Indexes
# pyproject.toml
[tool.uv]
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
[[tool.uv.index]]
name = "company"
url = "https://registry.company.com/simple"
[tool.uv.sources]
torch = { index = "pytorch" }Key Environment Variables
| Variable | Purpose |
|---|---|
UV_INDEX_URL | Default package index |
UV_EXTRA_INDEX_URL | Additional indexes (space-separated) |
UV_CACHE_DIR | Override cache directory |
UV_PYTHON_INSTALL_DIR | Override managed Python install dir |
UV_PYTHON_DOWNLOADS | auto (default), never, manual |
UV_NO_MODIFY_PATH | 1 to prevent installer from touching shell profiles |
UV_LINK_MODE | clone, copy, hardlink, or symlink |
UV_PROJECT_ENVIRONMENT | Override the venv path (default: .venv) |
UV_NO_SYNC | 1 to skip auto-sync in uv run |
UV_FROZEN | 1 to never update the lockfile |
UV_COMPILE_BYTECODE | 1 to compile .pyc files during install |
VIRTUAL_ENV | Respected by uv pip commands |
UV_HTTP_TIMEOUT | HTTP timeout in seconds (default: 30) |
Cache Management
uv uses a global cache at ~/.cache/uv (Linux) for deduplicating packages across projects.
# Show cache directory
uv cache dir
# Clear the entire cache
uv cache clean
# Clear cache for a specific package
uv cache clean requests
# Prune unreferenced cache entries
uv cache prune
# Override cache location
export UV_CACHE_DIR=/tmp/uv-cacheStorage Directories (Linux defaults)
| What | Path |
|---|---|
| Cache | ~/.cache/uv/ |
| Managed Python | ~/.local/share/uv/python/ |
| Tools | ~/.local/share/uv/tools/ |
| Tool binaries | ~/.local/bin/ |
| User config | ~/.config/uv/uv.toml |
| System config | /etc/uv/uv.toml |
These follow XDG conventions. Override with UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, etc.
Disable Configuration Discovery
# Ignore all config files
uv run --no-config main.py
# Use a specific config file
uv run --config-file /path/to/uv.toml main.py