Skip to content

Linux basicsFor beginnersDuration around 10 min.

How to install Python and uv on Ubuntu

Ubuntu comes with Python, but no longer allows pip to install into the system. This guide shows the way with a virtual environment and the faster way with uv, which manages packages, projects and Python versions in one tool.

Tested on with Python 3.12 on Ubuntu 24.04 LTS, Python 3.14 on Ubuntu 26.04 LTS and uv 0.13

At a glance

  • Ubuntu 24.04 comes with Python 3.12, Ubuntu 26.04 with Python 3.14 — pip only installs packages in its own environment.
  • uv installs itself into your home directory with one line and replaces pip, venv and the management of Python versions.
  • uv init creates a project, uv add adds packages, uv run executes code in the appropriate environment.

Prerequisites

  • A server with Ubuntu 24.04 or 26.04, such as a VPS or a Cloud Server, and a user with sudo privileges for step 1.

1. Check Python and add venv

python3 is installed. For virtual environments and pip, you need two packages that are often missing on lean servers:

Version and additions
python3 --version
sudo apt install -y python3-venv python3-pip

2. Packages in a virtual environment

Ubuntu rejects a pip install directly into the system so that system tools are not damaged:

pip without environment
error: externally-managed-environment
 
× This environment is externally managed

Create an environment instead and install there:

Environment with venv
python3 -m venv ~/venv
~/venv/bin/pip install requests
~/venv/bin/python -c 'import requests; print(requests.__version__)'

3. Install the uv tool

The script places uv in ~/.local/bin, without sudo. The second line adds the folder to the current session; new sessions know it automatically.

Install uv tool
curl -LsSf https://astral.sh/uv/install.sh | sh
source ~/.local/bin/env
uv --version
Output
uv 0.13.12

4. A project with uv

uv init creates a project, uv add writes packages to pyproject.toml and uv.lock and installs them in .venv. uv run executes commands in this environment — activation is not necessary.

Create project and use package
uv init demo
cd demo
uv add requests
uv run python -c 'import requests; print(requests.__version__)'
Files in the project
.python-version
.venv
README.md
pyproject.toml
src
uv.lock

The uv.lock file belongs in the repository

uv.lock records the exact versions of all packages. With uv sync, the same environment is created on another server.

5. Other Python versions

If a project needs a different version than the system, uv downloads it. The system Python remains untouched.

Add Python 3.13
uv python install 3.13
uv python list --only-installed
uv run --python 3.13 python --version

6. Fast replacement for pip: uv pip and uv tool

Even without a project, uv accepts the familiar commands of venv and pip:

Environment and package
uv venv ~/alt
uv pip install --python ~/alt/bin/python httpx

uv tool installs command-line tools in their own environment and places the command in ~/.local/bin:

Install tool
uv tool install ruff
ruff --version

Typical errors

  • externally-managed-environment: pip tried to install into the system. Use an environment or uv.
  • uv: command not found: The session does not know ~/.local/bin yet. Load ~/.local/bin/env or sign in again.
  • The virtual environment was not created successfully: python3-venv is missing on Ubuntu. Install it as in step 1.

We tested all commands in this guide on 2 December 2026 — with Python 3.12 on Ubuntu 24.04 LTS, Python 3.14 on Ubuntu 26.04 LTS and uv 0.13. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about Python and uv

Which Python version does Ubuntu have?

Ubuntu 24.04 comes with Python 3.12, Ubuntu 26.04 with Python 3.14. You can add other versions with uv python install.

What is uv?

A fast tool for Python packages and projects. It takes over the tasks of pip, venv and version management in one program.

May I install pip into the system with sudo?

Better not. System packages can interfere with Ubuntu tools; therefore, Ubuntu rejects this. There are environments for applications.

How do I update uv?

With uv self update if you set up uv via the installation script.

Do I still need an environment on the server if the application runs in Docker?

No. In the container, the Python of the image is the environment; uv can be used there in the same way.

Further reading

More tutorials

  • The scp command with examples: copy files over SSH

    Linux basicsFor beginnersabout 5 min

    scp copies files over an SSH connection — encrypted, with the same credentials as your login, and without an additional service on the server. This guide shows the commands for common use cases, each with an example to copy.

  • How to check your Ubuntu version, codename and kernel

    Linux basicsFor beginnersabout 2 min

    A single command in the terminal shows which Ubuntu version is running on a server. Here are the common ways with their output — for the version with point release, the codename, the kernel and the architecture.

  • How to remove a directory in Linux with rm and rmdir

    Linux basicsFor beginnersabout 5 min

    In Linux, you delete an empty folder with rmdir and a folder including its contents with rm -r. This tutorial shows both commands with their messages, the variants with and without prompting, and what to check before running rm -rf — because there is no recycle bin in the terminal.

A server for your Python projects

Every VPS and cloud server comes with Python; you set up uv with a single line.