Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Linux

How to Install Python on a VPS (Ubuntu, Debian, AlmaLinux and Windows)

How to install Python on a VPS guide by 99RDP

Python runs bots, web apps, scrapers, automation scripts and data jobs, and a VPS is a natural place to keep them running 24/7. Most Linux servers already include Python 3, but often not the version your project needs, and modern distributions block system-wide pip install. This guide shows how to check what you have, install the version you need the right way, set up virtual environments, and run a script permanently on a Linux or Windows VPS.

Quick answer

sudo apt update
sudo apt install python3 python3-venv python3-pip
python3 --version
python3 -m venv ~/myapp/venv && source ~/myapp/venv/bin/activate

Which Python version do you get?

Server OSDefault Python 3
Ubuntu 22.04 LTS3.10
Ubuntu 24.04 LTS3.12
Ubuntu 26.04 LTS3.14
Debian 133.13
AlmaLinux / Rocky Linux 93.9 (3.11 and 3.12 available as extra packages)
AlmaLinux / Rocky Linux 103.12

The newest release is Python 3.15 (October 2026). For production, the version your distribution ships is usually the best choice: it gets security updates automatically. Install a newer one only when your project needs it. Python 3.10 reached end of life in October 2026, so move projects off it.

Step 1: Update the server

# Ubuntu / Debian
sudo apt update && sudo apt upgrade -y

# AlmaLinux / Rocky Linux
sudo dnf upgrade -y
apt installing python3, pip and venv on an Ubuntu VPS followed by python3 --version
Installing Python 3 with apt

Step 2: Install Python 3, pip and venv

Ubuntu and Debian

sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential

python3-dev and build-essential let pip compile packages with C extensions.

AlmaLinux and Rocky Linux

sudo dnf install -y python3 python3-pip python3-devel gcc
# a newer version on EL9, side by side
sudo dnf install -y python3.12 python3.12-pip

Check the result:

python3 --version
pip3 --version

On most distributions, the command is python3, not python. On Ubuntu, sudo apt install python-is-python3 adds a python alias.

Creating and activating a Python virtual environment and installing packages with pip on a VPS
Working inside a virtual environment

Step 3: Use a virtual environment for every project

On Ubuntu 23.04+ and Debian 12+, pip install outside a virtual environment fails with externally-managed-environment. That's intended: it protects the Python packages the OS needs. Create a venv per project:

mkdir -p ~/myapp && cd ~/myapp
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install requests flask
deactivate

Inside the venv, python and pip point to the project's own copy. Save dependencies with pip freeze > requirements.txt and restore them with pip install -r requirements.txt.

For command-line tools you want available everywhere, use pipx: sudo apt install pipx, then pipx install black.

Diagram of Python virtual environments keeping each project packages separate from the system Python
Why each project gets a venv

Step 4: Install a newer Python version (optional)

With uv (fast and distribution-independent)

curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.15
uv venv --python 3.15 ~/myapp/venv

uv downloads pre-built Python versions into your home directory without touching the system Python, and installs packages very quickly.

With the deadsnakes PPA (Ubuntu LTS only)

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.15 python3.15-venv

Never replace or re-link /usr/bin/python3 to a different version; tools like apt depend on the default one. Call the new version explicitly (python3.15) or use it inside a venv.

With pyenv or from source

pyenv builds any version and lets you switch per folder. Building from source works too: install the build dependencies, then ./configure --enable-optimizations && make -j"$(nproc)" && sudo make altinstall. altinstall avoids overwriting the system python3.

Step 5: Run your script 24/7 with systemd

A script started in an SSH session stops when you disconnect. Run it as a service instead. Create /etc/systemd/system/myapp.service:

[Unit]
Description=My Python app
After=network-online.target

[Service]
User=youruser
WorkingDirectory=/home/youruser/myapp
ExecStart=/home/youruser/myapp/venv/bin/python app.py
Restart=always
Environment=PYTHONUNBUFFERED=1

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
journalctl -u myapp -f        # live logs

Python on a Windows VPS

  1. Install from python.org, or with winget (winget search Python.Python lists the available versions, then winget install the one you want).
  2. If you use the classic installer, tick Add python.exe to PATH.
  3. Check with py --version or python --version, and create venvs with py -m venv venv and venv\Scripts\activate.
  4. To run a script permanently, use Task Scheduler (run at startup, whether user is logged on or not) or a service wrapper such as NSSM.

Troubleshooting

  • "python: command not found": use python3, or install python-is-python3.
  • "externally-managed-environment": activate a venv first, or use pipx or apt.
  • "No module named venv" / "ensurepip is not available": install python3-venv (or python3.X-venv for that version).
  • pip fails building a package: install python3-dev and build-essential (Debian/Ubuntu) or python3-devel and gcc (EL).

Frequently asked questions

How do I install Python on a Linux VPS?

On Ubuntu or Debian run sudo apt install python3 python3-pip python3-venv; on AlmaLinux or Rocky run sudo dnf install python3 python3-pip.

Which Python version should I use on my server?

The version your OS ships is easiest to maintain. If your project needs newer features, install Python 3.14 or 3.15 alongside it with uv, pyenv or deadsnakes.

Why can't I pip install on Ubuntu 24.04?

The system Python is marked as externally managed. Create a virtual environment with python3 -m venv and install packages there.

How do I keep a Python script running on a VPS?

Run it as a systemd service with Restart=always on Linux, or with Task Scheduler or NSSM on Windows.

Nishant Kumar, Sr. Server Engineer at 99RDP
Written byNishant KumarSr. Server Engineer, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Linux guides

All Linux guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services