Set up uv on Ubuntu

Basic python

Set up uv on Ubuntu

Goals of this page #

  • Install Python 3.13 and uv on Ubuntu 22.04 / 24.04 LTS
  • Create, activate, and manage a virtual environment for your study projects
  • Spot common pitfalls and know the checks to run when something fails

Prerequisites #

ItemDetails
PrivilegesAbility to run sudo for package management
TerminalOpen with Ctrl + Alt + T or from the application menu
Working folderExample: ~/projects/my-app (adjust if desired)

1. Install Python 3.13 #

Ubuntu窶冱 default repositories don窶冲 ship Python 3.13 yet, so add the deadsnakes PPA.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.13 python3.13-venv python3.13-dev python3.13-distutils
python3.13 --version

Seeing Python 3.13.x confirms success.

2. Install uv #

curl -LsSf https://astral.sh/uv/install.sh | sh
~/.local/bin/uv --version

If the command is not found, add ~/.local/bin to your PATH:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

3. Create the project folder and virtual environment #

mkdir -p ~/projects/my-app
cd ~/projects/my-app
uv venv --python 3.13 .venv
source .venv/bin/activate

When you see (.venv) in the prompt, the environment is active. Use deactivate to exit.

庁 You can also skip activation and run uv run python script.py; uv will reuse the environment automatically.

4. Add and sync libraries #

uv pip install numpy pandas
uv pip list
uv pip sync requirements.txt
  • uv pip install: add packages
  • uv pip list: inspect what窶冱 installed
  • uv pip sync: rebuild the environment from requirements.txt

5. Connect with editors (VS Code, etc.) #

  • In VS Code install the 窶弃ython窶・extension, press Ctrl+Shift+P, choose Python: Select Interpreter, and pick .venv/bin/python.
  • For CLI editors such as vim/neovim, simply start them from the shell where the environment is activated.

6. Common issues #

IssueFix
add-apt-repository missingRun sudo apt install software-properties-common
uv still not in PATHAppend ~/.local/bin to PATH and reload the shell
Permission denied when creating .venvCheck directory ownership (ls -ld .) and adjust with chown if necessary

7. Clean-up #

  • Leave the environment: deactivate
  • Remove the environment: rm -rf .venv
  • Record dependencies: uv pip freeze > requirements.txt

Your Ubuntu environment now runs Python 3.13 with uv. For comparison, review the guides for Windows and macOS, then continue to the syntax chapter and start coding.

When you’re ready, move on to the next lesson to start learning Python.