To install uv on Ubuntu 26.04 or 24.04, use Astral’s standalone installer. It installs into your user account and does not require Python first. If you already manage Python command-line applications with pipx, that is another supported route.
uv manages Python versions, project environments and packages. This guide takes you from installation to a working project, then shows how to update dependencies and recreate its environment. If a step fails, leave a comment with the error or contact us.
Before you begin
Use Ubuntu 26.04 or 24.04 Desktop or Server, a Bash terminal and internet access. Ubuntu on WSL uses these Linux commands inside its Ubuntu terminal.
You need sudo only for Ubuntu packages. Run the uv installer and project commands as your normal user.
Keep Ubuntu’s /usr/bin/python3. Do not replace it, remove it or use sudo uv to install project packages.
Choose one uv installation route. The practice project uses Python 3.12 as a deliberate example, not as a claim about the newest Python.
Open a terminal with Ctrl+Alt+T on Ubuntu Desktop and check:
Ubuntu terminal
cat /etc/os-release
type -a uv uvx
A command-not-found message is expected if uv is absent. If it is already installed, run uv --version and identify how you installed it before adding another copy. The first PATH match is the one your shell runs.
Step 2: Install the download tools
These packages download HTTPS files and let you inspect the installer:
Ubuntu terminal
sudo apt update
sudo apt install curl ca-certificates less
APT may report that they are already installed. Review its proposed changes before confirming. You do not need Rust or a compiler to use uv’s prebuilt installer.
Step 3: Download and inspect the installer
The installer runs downloaded code under your account. Save it first so you can read it. Keep these commands and the next step in the same terminal:
Press q to leave less. If the download failed, stop and fix that error. Continue only if you trust Astral and are comfortable running this script. HTTPS protects the connection; inspection is not an independent security audit.
Step 4: Run the installer and check uv
Run the saved script without sudo:
Ubuntu terminal
sh "$uv_setup_dir/install.sh"
For the default installation, load the environment file it creates and check both commands:
Expect version numbers and, for the default route, a path under ~/.local/bin. If you customized the install directory, follow the path printed by the installer instead. A new terminal should pick up its shell configuration changes. See the PATH fix below if it does not. Astral’s installation documentation also covers direct binary downloads and other platforms.
Installation finished
Continue to create your first project. The pipx route below is an alternative installation, not another required step.
2. Alternative: install uv with pipx
Step 1: Install pipx and configure its command path
Close and reopen the terminal after ensurepath. If APT cannot find pipx, check your Ubuntu repository configuration, including Universe. pipx keeps uv in its own environment rather than installing it into Ubuntu’s system Python.
Step 2: Install and verify uv
In the new terminal, run:
Ubuntu terminal
pipx install uv
uv --version
uvx --version
pipx list
Use pipx upgrade uv for updates and pipx uninstall uv for removal. Do not use uv self update for this route. Avoid sudo pip install uv or bypassing Ubuntu’s externally-managed-environment protection.
Ubuntu’s current package listings do not offer the uv CLI for 26.04 or 24.04, so sudo apt install uv is not an installation route for these releases. A community astral-uv Snap is also available, published by Alex Lowe rather than Astral. Check the publisher and confinement before choosing a different package.
3. Create and run your first Python project
The exercise prints a small project-status table with the Rich library. It needs no API key, account or external service after packages have downloaded. All remaining project commands run from the same practice directory.
Step 1: Make a new practice directory
Use a unique directory so these steps cannot overwrite an existing project:
If any command fails, stop here. --no-package requests a simple script project rather than a distributable package. --vcs none skips Git setup. uv creates starter files and records the requested Python version; the environment and lockfile are created when needed. Run pwd and save the directory path so you can return later.
Step 2: Add the library
Declare Rich as a project dependency:
Ubuntu terminal
uv add rich
uv resolves the dependency, updates pyproject.toml and uv.lock, and installs packages into .venv. It can download a suitable Python interpreter if one is missing. Installing uv itself did not require Python.
Step 3: Write the example
The following command replaces only the generated main.py in this new practice project. Do not run it in an existing project containing your own work:
uv run main.py
uv run python -c "import sys; print(sys.executable)"
Expect a table showing a Python 3.12 patch version, .venv and Working. The executable path should end in /.venv/bin/python. Exact patch numbers, colors and table borders can vary. There is no need to activate the environment before using uv run.
File or folder
Why it matters
main.py
Your program. Keep it with the project.
pyproject.toml
Project metadata, supported Python versions and dependency declarations.
.python-version
The Python version requested for local project commands. A minor-version pin does not freeze a patch release.
uv.lock
Resolved dependency versions. Keep this with the project to reuse the same resolution.
.venv/
The local Python environment. Recreate it when needed; do not commit it to Git.
When you return, open a terminal in the saved project directory and run uv run main.py. Before opening someone else’s project, review its code and dependencies: installing packages or running a project can execute code.
4. Manage dependencies without losing track of them
Step 1: Inspect the dependency tree
From the practice project, run:
Ubuntu terminal
uv tree
Rich can depend on other packages. These indirect, or transitive, dependencies are resolved in the lockfile too. You normally declare the libraries your own code uses directly.
Step 2: Add a development tool
Ruff checks Python code for common mistakes. Keep it in the development dependency group:
Ubuntu terminal
uv add --dev ruff
uv run ruff check main.py
The example should report All checks passed!. This is a lint check, not an application test. The dev group is included by default. Use uv remove --dev ruff if you no longer want it.
Step 3: Upgrade a dependency deliberately
Save or commit the working project first. To update Rich within its declared version constraints:
Ubuntu terminal
uv lock --upgrade-package rich
uv sync
uv run main.py
The first command updates the lockfile; the second installs the selected versions. Review changed files and check your program afterward. To reconsider all dependency versions within their constraints, use uv lock --upgrade, then sync and run your project checks. A routine sync does not automatically select every newly released version.
Step 4: Add and remove an optional package
This demonstration uses a library the example does not import:
Ubuntu terminal
uv add humanize
uv remove humanize
Both commands update project metadata, the lockfile and the environment. Do not remove Rich while main.py still imports it. Avoid mixing manual pip installs into a uv-managed project: packages missing from project declarations can disappear on the next exact sync.
These commands follow Astral’s locking and syncing rules. A lockfile records dependency choices; it does not guarantee identical behavior across every operating system, native library or Python patch release.
5. Recreate an environment from the lockfile
When moving your own project to another machine, keep the source, pyproject.toml, uv.lock and .python-version. Install uv there, enter the project directory and run:
Ubuntu terminal
uv sync --locked
uv run --locked main.py
--locked requires the lockfile to agree with the project metadata rather than silently rewriting it. A missing .venv is created. Missing interpreters and packages may need downloads. You do not need to copy an environment between machines.
Sync can remove undeclared packages
uv sync performs an exact sync by default. It can remove packages from the project environment if they are not selected by the project’s dependencies and groups. Declare needed packages with uv add. Do not point uv at a shared environment containing unrelated work.
Optional: recreate this practice environment without deleting it
Close editors or processes using this practice environment first. This block renames the local .venv to a backup, then creates a replacement from the lockfile. Run it only inside the practice project:
Ubuntu terminal
if [ -d .venv ] && [ ! -e .venv.backup ]; then
mv .venv .venv.backup &&
uv sync --locked &&
uv run --locked main.py
else
printf '%s\n' 'Stop: .venv is absent or .venv.backup already exists.'
fi
The same table should appear. The backup remains until you remove it deliberately. If recreation fails, keep that backup, fix the reported issue and retry uv sync --locked. A moved virtual environment is not a portable runnable backup; restore its original name before trying to reuse it.
6. Choose Python versions and connect your editor
See available Python versions and the current project interpreter
uv can use an existing compatible interpreter or download one managed separately from Ubuntu:
Ubuntu terminal
uv python list
uv run python --version
/usr/bin/python3 --version
These last two versions can differ. The project uses its selected interpreter; Ubuntu keeps its own system Python. uv-managed downloads come from Astral’s python-build-standalone distributions, not Ubuntu APT packages.
Select Python 3.12 for a project that supports it
The practice project already requests this version. For another project, check its Python requirements before changing the selection:
Pinning writes .python-version. It does not rewrite the project’s requires-python compatibility range. If those requirements conflict, read the error and choose a compatible version rather than claiming unsupported compatibility. Do not use uv’s optional default-executable feature to replace your usual python3 for this exercise.
In VS Code, open the whole project folder and use Python: Select Interpreter from the Command Palette to select .venv/bin/python. If it is missing, run uv sync first. Other editors should use the same project interpreter. Keep a uv-run terminal workflow even if the editor does not activate the environment automatically.
7. Run Python command-line tools with uvx
Use uv run for a command that should use your project dependencies. Use uvx, the shortcut for uv tool run, for an isolated command-line tool. For example:
Ubuntu terminal
uvx ruff --version
This runs Ruff from an isolated cached environment. It does not add Ruff to your project or promise the same version as your project’s dev group. To check this project using its declared Ruff version, keep using uv run ruff check main.py. Only run tools whose source you trust.
Optional: install a tool for repeated use
If you want a standalone ruff command outside projects:
Ubuntu terminal
uv tool install ruff
uv tool update-shell
Open a new terminal, then run ruff --version. Update this standalone tool with uv tool upgrade ruff, list it with uv tool list, or remove it with uv tool uninstall ruff. These operations are separate from your project’s Ruff dependency.
8. Update uv using the method you installed
Standalone installer: update uv itself
For the upstream script installation:
Ubuntu terminal
uv self update
uv --version
This updates the manager. It does not upgrade all your project dependencies, standalone tools or every Python interpreter.
pipx: upgrade its uv installation
For the pipx route:
Ubuntu terminal
pipx upgrade uv
uv --version
Keep using pipx for this installation. If the version still looks unchanged, inspect type -a uv for another copy earlier on PATH.
9. Fix common uv problems on Ubuntu
Issue 1: uv: command not found
For a default standalone install, check whether the binary exists, then load the environment file:
Ubuntu terminal
ls -l "$HOME/.local/bin/uv" "$HOME/.local/bin/env"
. "$HOME/.local/bin/env"
uv --version
type -a uv
If either file is absent, do not keep sourcing it. Check the installer output or your custom installation path. For pipx, run pipx ensurepath and reopen the terminal. Do not copy binaries into /usr/bin as a PATH repair.
Issue 2: externally-managed-environment
This usually comes from trying to install uv with pip into Ubuntu’s system Python. Use the standalone installer or the pipx route above. Do not delete the EXTERNALLY-MANAGED marker or add --break-system-packages as a workaround.
Issue 3: ModuleNotFoundError or the editor cannot import Rich
Check the project directory and selected interpreter:
Ubuntu terminal
pwd
ls pyproject.toml uv.lock
uv sync --locked
uv run main.py
uv run python -c "import sys; print(sys.executable)"
A bare python3 main.py may use Ubuntu’s interpreter instead of .venv. Use uv run, and select the same environment in the editor. For your own project, add missing direct dependencies with uv add.
Issue 4: no compatible Python or dependency resolution failed
Read the Python range and package conflict in the error. A requested interpreter must satisfy requires-python and package requirements. Inspect:
Ubuntu terminal
cat .python-version
cat pyproject.toml
uv python list
Install a compatible version and pin it deliberately. Do not solve a conflict by replacing /usr/bin/python3 or blindly removing version constraints. Some packages do not yet support a newly released Python.
Issue 5: a package needs a compiler or native library
Some dependencies lack a compatible prebuilt wheel and must compile locally. Read that package’s build instructions. A compiler error may require Ubuntu build-essential; a missing library header needs that library’s development package. System python3-dev headers may not match a uv-managed interpreter. Do not install unrelated packages or use sudo uv to bypass the failure.
Issue 6: download or certificate failure
Check the connection, system time and certificate bundle:
Correct an inaccurate clock. On a managed network, use your organization’s trusted certificate and proxy settings; current uv supports --system-certs when the required certificate is in the system trust store. Do not disable TLS verification. A blocked package index or Python download may need separate network access.
Resume after fixing an error
Retry the same installation route. If uv works and the problem was a project download, return to the directory containing pyproject.toml and run uv sync --locked, then uv run --locked main.py. If uv reports a stale lockfile after an intentional metadata edit, review that change and run uv lock before syncing. Keep your source and lockfile while repairing an environment.
10. Remove uv and clean up only what you choose
Step 1: Inspect managed data before removal
Do this while uv still works:
Ubuntu terminal
uv tool list
uv python list --only-installed
uv cache dir
uv python dir
uv tool dir
type -a uv uvx
Removing the uv binaries does not delete your projects, their .venv directories, managed Python installations or installed tools. Removing a managed interpreter can break environments that reference it.
Step 2: Optionally remove a tool or cached downloads
If you installed standalone Ruff in the optional section, remove it before uv:
Ubuntu terminal
uv tool uninstall ruff
This affects the standalone tool, not a project dependency. You can also run uv cache clean to clear cached downloads and builds. Keep the cache if you want to avoid downloading those files again. Do not recursively delete the paths printed above without inspecting their contents and dependent environments.
Step 3A: Remove the default standalone binaries
Only use this block if type -a confirms that your intended standalone installation uses these exact default paths. The -i option asks before each file is removed:
For a custom installation, inspect and remove its exact binary files instead. Do not delete the shared ~/.local/bin directory or its env file: other applications can use them. Inspect your shell startup configuration before removing any installer-added PATH entry.
Step 3B: For pipx, uninstall through pipx instead
Use this alternative for the pipx installation:
Ubuntu terminal
pipx uninstall uv
Do not manually remove pipx-managed command links using the standalone block. Keep pipx if you use it for other applications.
Ubuntu terminal
hash -r
type -a uv uvx
Command-not-found messages are expected when no copy remains. Keep your source, pyproject.toml and uv.lock if you may return to the project later. Remove practice folders or managed Python versions only when you have checked that nothing still needs them.
Not for the standalone installer. uv can discover an existing compatible Python or download a managed interpreter when needed. The pipx installation route uses Python through Ubuntu's pipx package.
Does uv replace Ubuntu's system Python?
No. Keep /usr/bin/python3 managed by Ubuntu. uv projects use their selected interpreter and a separate environment. Do not remove system Python or redirect its executable to a uv-managed installation.
Do I need to activate .venv before using uv run?
No. In a project, uv run selects and prepares the project environment before running the command. An editor or a separate terminal command may still need the project interpreter selected explicitly.
What is the difference between uv add and uv pip install?
uv add records a project dependency and updates its lockfile and environment. uv pip install installs into a selected environment without declaring the package as a project dependency. For a uv-managed project, use uv add so future syncs can reproduce it.
Should I keep uv.lock in Git?
Yes, keep the lockfile with a uv-managed project, along with its source and pyproject.toml. Do not commit .venv. The lockfile records dependency choices; Python, operating-system and native-library requirements still matter.
Does uv sync upgrade every package?
No. It normally reuses compatible locked versions. Request upgrades deliberately, such as with uv lock –upgrade-package rich, then sync and check the program. Exact sync can remove undeclared packages from the environment.
Can I use uv with an existing requirements.txt?
Yes. uv can install requirements into a virtual environment, and uv add -r requirements.txt can import dependencies into a uv project. Back up the project, review its existing configuration and follow Astral's migration guide before switching workflows.