Is there a way to configure uv to store all virtual environments in a central location…
- User
Is there a way to configure
uvto store all virtual environments in a central location instead of in the application folders? - Assistant
Yes, you can configure
uv(a fast Python package manager and virtual environment manager) to store all virtual environments in a central location, instead of creating them inside each application/project directory.
✅ How to configure
uvto use a central location for virtual environmentsStarting from
uvversion 0.1.22, it honors the same environment variable used by virtualenv:UV_VENV_HOMEThis environment variable allows you to specify a global path where all virtual environments will be stored.
🔧 Steps to Set a Central Venv Directory
-
Choose a central directory, for example:
~/.virtualenvs -
Set the environment variable
UV_VENV_HOME:-
On Linux/macOS (add to
~/.bashrc,~/.zshrc, etc.):export UV_VENV_HOME="$HOME/.virtualenvs" -
On Windows (PowerShell):
$env:UV_VENV_HOME = "$HOME\.virtualenvs" -
Or for temporary use only in current shell:
UV_VENV_HOME="$HOME/.virtualenvs" uv venv
-
-
Use
uv venvoruv pip installas usual:uv venvThis will now create and manage the virtual environment under:
~/.virtualenvs/<some-hash-or-name>
📁 Notes
uvuses hashed names for venv folders (based on project path), so environments are still uniquely associated with specific projects, even in a central location.- If you delete a project folder but want to clean up central venvs, you may have to manually delete the unused folders under
~/.virtualenvs.
🧪 Verify it's working
After running
uv venv, check your central venv directory:ls ~/.virtualenvsYou should see new folders created there.
Let me know if you want help also making this compatible with tools like
direnvorpyenv! -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.