How to Install Python with uv on Ubuntu 22.04 (Latest Version, Switching Versions)

This guide installs the latest Python on an Ubuntu 22.04 server with uv, then covers installing several versions, settin…

Ubuntu 22.04Python 3.15x86_64About 9 min

Verified guide

This guide was verified by creating a cloud server and running every command in it, from start to finish, exactly as written.

OS
Ubuntu 22.04.5 LTS · x86_64
Installed version
Python 3.15.0, Python 3.13.16, uv 0.13.1
Test server
DigitalOcean · 2 vCPU / 2 GB RAM / 60 GB SSD (s-2vcpu-2gb, sgp1)
Last checked
2026-10-16

This guide contains affiliate links. If you sign up through them, Codesand may earn a commission. This doesn't affect the content or our assessments.

This guide installs the latest Python on an Ubuntu 22.04 server with uv, then covers installing several versions, setting the Python version per project, virtual environments and package installation, fixing the uv command-not-found error and ModuleNotFoundError, and removing everything cleanly.

1. Requirements

  • One Ubuntu 22.04 LTS server or PC
  • A regular user account with sudo privileges
  • An internet connection (files are downloaded from GitHub and PyPI)

If you don't have a server, try creating a DigitalOcean Droplet. Every step in this guide was verified on a Droplet (2 vCPU, 2 GB memory, 60 GB SSD, Ubuntu 22.04, Singapore) using a regular user account with sudo privileges.

2. Check the state before installing

Ubuntu 22.04 comes with Python 3.10. System programs use this Python, so do not remove it or replace it with another version.

python3 --version
Python 3.10.12

There is no python command. Ubuntu provides Python only under the name python3.

python --version
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

pip3, which installs packages, is not available either, and venv, which creates virtual environments, cannot be used right away.

pip3 --version
Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
python3 -m venv myenv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: /home/devuser/myenv/bin/python3

The failed command leaves a half-created myenv folder behind, so delete it. There is no output.

rm -rf myenv

Python 3.10 reached end of life in October 2026, and the latest Python on the day this guide was verified was 3.15. This guide leaves the system Python as it is and installs the latest Python separately in your user folder with uv. uv is a single tool that handles Python installation, version changes, virtual environments, and package installation. Because it downloads prebuilt Python, installation finishes within a minute and does not need sudo.

3. Install uv

Download and run the uv install script. curl -LsSf downloads without a progress display and shows an error if the download fails. The downloaded script is passed to | sh and runs right away. This guide installed uv 0.13.1, the latest version on the day it was verified.

curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.13.1 x86_64-unknown-linux-gnu
installing to /home/devuser/.local/bin
  uv
  uvx
everything's installed!

To add $HOME/.local/bin to your PATH, either restart your shell or run:

    source $HOME/.local/bin/env (sh, bash, zsh)
    source $HOME/.local/bin/env.fish (fish)

uv is installed in the ~/.local/bin folder, and a line that adds this folder to the command path (PATH) is appended to the end of ~/.bashrc and ~/.profile.

4. Verify the uv installation

If you run uv right away in the terminal where you installed it, you get a message that the command cannot be found. This is because the terminal was opened before the PATH line was added.

uv --version
uv: command not found

Run the command below as the install message suggests, or close the terminal and open a new one (for SSH, disconnect and reconnect). There is no output.

source $HOME/.local/bin/env
uv --version
uv 0.13.1 (x86_64-unknown-linux-gnu)

5. Install the latest Python

If you do not specify a version, uv installs the latest Python.

uv python install
Installed Python 3.15.0 in 1.55s
 + cpython-3.15.0-linux-x86_64-gnu (python3.15)

Check the list of installed Python versions. The Python installed by uv and the system Python (/usr/bin) are shown together.

uv python list --only-installed
cpython-3.15.0-linux-x86_64-gnu     .local/bin/python3.15 -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu     .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.10.12-linux-x86_64-gnu    /usr/bin/python3.10
cpython-3.10.12-linux-x86_64-gnu    /usr/bin/python3 -> python3.10

uv registers the installed Python only under a versioned name such as python3.15. So python3.15 runs, but python still cannot be found.

python3.15 --version
Python 3.15.0
python --version
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

To run Python 3.15 as python and python3 as well, install it again with --default. Python is already downloaded, so only the names are added. This option is still experimental, so a warning is shown, but the installation works.

uv python install 3.15 --default
warning: The `--default` option is experimental and may change without warning. Pass `--preview-features python-install-default` to disable this warning
Installed Python 3.15.0 in 81ms
 + cpython-3.15.0-linux-x86_64-gnu (python, python3)
python --version
Python 3.15.0
python3 --version
Python 3.15.0
which python
/home/devuser/.local/bin/python

6. Install another version

If you need another version, specify the version number. Writing 3.13 installs the latest release in the 3.13 series.

uv python install 3.13
Installed Python 3.13.16 in 1.65s
 + cpython-3.13.16-linux-x86_64-gnu (python3.13)
uv python list --only-installed
cpython-3.15.0-linux-x86_64-gnu     .local/bin/python3.15 -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu     .local/bin/python3 -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu     .local/bin/python -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu     .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.13.16-linux-x86_64-gnu    .local/bin/python3.13 -> .local/share/uv/python/cpython-3.13-linux-x86_64-gnu/bin/python3.13
cpython-3.13.16-linux-x86_64-gnu    .local/share/uv/python/cpython-3.13-linux-x86_64-gnu/bin/python3.13
cpython-3.10.12-linux-x86_64-gnu    /usr/bin/python3.10
cpython-3.10.12-linux-x86_64-gnu    /usr/bin/python3 -> python3.10

Python 3.13 can be run as python3.13, and python stays at 3.15. Step 8 explains how to use a different version per project.

7. Create your first project and install a package

uv creates a virtual environment (.venv) in each project folder and manages packages separately for each project. Open a new terminal and create the hello-python project. --no-package means the project starts with a single main.py instead of a distributable package layout.

uv init --no-package hello-python
Initialized project `hello-python` at `/home/devuser/hello-python`
cd hello-python
ls -a
.  ..  .git  .gitignore  .python-version  README.md  main.py  pyproject.toml

.python-version is a file that records the Python version this project uses. It contains 3.15, the newest of the installed Python versions. main.py contains an example that prints a greeting.

cat .python-version
3.15
cat main.py
def main():
    print("Hello from hello-python!")


if __name__ == "__main__":
    main()

Run project files with uv run. On the first run, it creates the virtual environment (.venv) and then runs the file.

uv run main.py
Using CPython 3.15.0
Creating virtual environment at: .venv
Hello from hello-python!

Install packages with uv add. Let's install the requests package, which sends HTTP requests. The package goes only into the project's virtual environment and is recorded in pyproject.toml.

uv add requests
Resolved 6 packages in 154ms
Prepared 5 packages in 41ms
Installed 5 packages in 9ms
 + certifi==2026.7.22
 + charset-normalizer==3.5.2
 + idna==3.20
 + requests==2.34.2
 + urllib3==2.8.0

Replace main.py with code that uses requests and run it. The first line writes the quoted text to the file, so it has no output.

echo "import sys, requests; print('Hello Python', sys.version.split()[0], 'requests', requests.__version__)" > main.py
uv run main.py
Hello Python 3.15.0 requests 2.34.2

If you run the same file directly with python, you get an error that requests cannot be found. This is because requests is installed only in the project's virtual environment.

python main.py
Traceback (most recent call last):
  File "/home/devuser/hello-python/main.py", line 1, in <module>
    import sys, requests; print('Hello Python', sys.version.split()[0], 'requests', requests.__version__)
    ^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'requests'

If you want to run it with python without uv run, activate the virtual environment. The activate command has no output. When you are done, turn it off with deactivate.

source .venv/bin/activate
python --version
Python 3.15.0
python main.py
Hello Python 3.15.0 requests 2.34.2
deactivate

8. Set the Python version per project

You can set the version with --python when you create a project. Go back to your home folder and create old-project, which uses Python 3.13.

cd ~
uv init --no-package --python 3.13 old-project
Initialized project `old-project` at `/home/devuser/old-project`
cd old-project
cat .python-version
3.13

Check which Python runs in this project with uv run python --version.

uv run python --version
Using CPython 3.13.16
Creating virtual environment at: .venv
Python 3.13.16

To upgrade the version later, use uv python pin. The .python-version file changes, and the virtual environment is recreated with the new version on the next run.

uv python pin 3.15
Updated `.python-version` from `3.13` -> `3.15`
uv run python --version
Using CPython 3.15.0
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Python 3.15.0

You cannot go down to a lower version directly. See the requires-python item in step 9.

9. Troubleshooting

uv: command not found

This means you ran the command in a terminal that was opened before uv was installed. That terminal was opened before ~/.local/bin was added to PATH. Close the terminal and open a new one, or run source $HOME/.local/bin/env. If a new terminal shows the same message, check that the PATH line exists with grep -n 'local/bin/env' ~/.bashrc.

ModuleNotFoundError: No module named 'requests'

Packages installed with uv add exist only in the project's virtual environment (.venv). If you run python main.py directly, a Python outside the virtual environment runs and cannot find the package. Run it with uv run main.py, or activate the virtual environment with source .venv/bin/activate first.

python main.py
Traceback (most recent call last):
  File "/home/devuser/hello-python/main.py", line 1, in <module>
    import sys, requests; print('Hello Python', sys.version.split()[0], 'requests', requests.__version__)
    ^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'requests'
error: The requested Python version `3.13` is incompatible with the project `requires-python` value of `>=3.15`.

The Python version used when the project was created is recorded as the minimum version in requires-python in pyproject.toml, so you cannot uv python pin a lower version. If you really need a lower version, first lower the requires-python value in pyproject.toml, or create the project with --python from the start as in step 8.

uv python pin 3.13
error: The requested Python version `3.13` is incompatible with the project `requires-python` value of `>=3.15`.
The virtual environment was not created successfully because ensurepip is not available.

This message appears when you run python3 -m venv with the system Python (3.10). Ubuntu's system Python lacks the package needed to create virtual environments. Projects created with uv do not need this package because uv creates the virtual environment itself. If you need to create a virtual environment with the system Python, install the package with sudo apt install python3.10-venv as the message suggests.

10. Uninstall

Go back to your home folder and remove all Python versions installed by uv. The names registered in ~/.local/bin, such as python and python3, are removed as well. The system Python is not removed.

cd ~
uv python uninstall --all
Searching for Python installations
Uninstalled 2 versions in 156ms
 - cpython-3.13.16-linux-x86_64-gnu (python3.13)
 - cpython-3.15.0-linux-x86_64-gnu (python, python3, python3.15)

Clear the cache where uv keeps downloaded files.

uv cache clean
Clearing cache at: .cache/uv
Removed 156 files (1.0MiB)

Delete the uv tool folder and the practice project folders, then delete the uv programs and the PATH setup files (env, env.fish). Neither command has output.

rm -rf "$(uv tool dir)" ~/hello-python ~/old-project
rm ~/.local/bin/uv ~/.local/bin/uvx ~/.local/bin/env ~/.local/bin/env.fish

Check and delete the lines added to ~/.bashrc and ~/.profile in step 3. sed -i edits the file in place, and /local\/bin\/env/d deletes lines that contain local/bin/env.

grep -n 'local/bin/env' ~/.bashrc ~/.profile
/home/devuser/.bashrc:119:. "$HOME/.local/bin/env"
/home/devuser/.profile:29:. "$HOME/.local/bin/env"
sed -i '/local\/bin\/env/d' ~/.bashrc ~/.profile
ls -a ~/.local/bin
.  ..

Close the terminal, open a new one, and check. If uv cannot be found and python3 is back to the system Python, everything has been removed.

uv --version
uv: command not found
python3 --version
Python 3.10.12

Try it yourself

No server yet? You can spin up an Ubuntu server in a few minutes with one of these providers. We verified this guide on DigitalOcean.