Python 3.13 delivers the latest CPython runtime with free-threaded builds (PEP 703 preview) that remove the Global Interpreter Lock, faster startup through improved bytecode optimization, sharper error messages for debugging, and refined typing with deferred annotation evaluation (PEP 649). Teams testing multi-threaded scalability, benchmarking the newest performance improvements, or preparing for long-term projects benefit from upstream security support through October 2029.
This guide covers installing Python 3.13 on Ubuntu via the Deadsnakes PPA or compiling from source with custom flags, configuring pip in externally managed environments, creating virtual environments, and switching between interpreters without affecting Ubuntu’s system Python.
When to Choose Python 3.13 on Ubuntu
Compare Python Releases for Ubuntu
Python 3.13 is the leading-edge interpreter for Ubuntu systems that need the newest language features or want to evaluate the free-threaded build. Use the comparison below to decide when Python 3.13 is the right fit versus sticking with earlier releases.
| Python Version | Availability on Ubuntu | Choose It When | Trade-offs |
|---|---|---|---|
| Python 3.8 | Deadsnakes PPA or source build only | Legacy applications pinned to EOL runtimes, compatibility testing, and transitional migrations | End-of-life October 2024, no upstream security patches, containers strongly recommended |
| Python 3.10 | Ubuntu 22.04 LTS default, Deadsnakes PPA for newer releases | Production environments prioritizing stability and Canonical security coverage through October 2026 | Older feature set, many new libraries optimize for 3.11+, PPA required on 24.04 LTS |
| Python 3.11 | Deadsnakes PPA for all releases | CPU-bound workloads seeking major speed gains, exception groups, precise error locations | Community-maintained packages, not default on any supported Ubuntu release |
| Python 3.12 | Ubuntu 24.04 LTS default, Deadsnakes PPA for 22.04 LTS | General-purpose development with LTS security coverage through October 2028 | Ubuntu 22.04 LTS requires PPA, fewer concurrency improvements than 3.13 |
| Python 3.13 | Deadsnakes PPA for 24.04 LTS and 22.04 LTS, source builds for custom needs | Teams testing free-threaded CPython preview, projects adopting newest language features and typing changes, forward-looking development targeting upstream support through October 2029 | Not in Ubuntu 24.04 LTS repositories, community packages lack guaranteed security SLAs, some third-party wheels may lag initial releases |
| Python 3.14 | Deadsnakes PPA for 24.04 LTS and 22.04 LTS when published; source builds available immediately | Early adopters validating continued free-threaded work, benchmarking the latest interpreter, planning for support through October 2030 | Not in Ubuntu repositories, PPA patches can trail upstream, some wheels lag new releases |
Stick with Python 3.12 on Ubuntu 24.04 LTS when you prefer Canonical-managed security updates. Use Python 3.13 on development workstations, CI runners, or isolated services that benefit from the latest interpreter improvements, and plan to move to Python 3.14 when you want the longer security runway. Avoid replacing the system Python that ships with Ubuntu.
Key Reasons to Choose Python 3.13
Python 3.13 stands out for:
- Free-threaded runtime preview: Optional
--disable-gilbuilds (PEP 703) let you evaluate multi-threaded scalability without the Global Interpreter Lock. - Typing and error clarity: Deferred evaluation of annotations (PEP 649) and sharper error messages improve debugging and large project maintainability.
- Performance refinements: Faster startup, better bytecode optimization, and continued gains over Python 3.11 and earlier releases.
- Security window through October 2029: Upstream support runs five years from release, giving modern features and a long runway for updates.
- Future-facing ecosystem: Major frameworks quickly add wheels for new Python versions, and early 3.13 testing catches compatibility issues before production cutovers.
Pre-Flight Checklist
Before installing Python 3.13, verify your system state to avoid redundant installs or conflicts:
# Check if Python 3.13 is already installed
python3.13 --version 2>/dev/null && echo "Python 3.13 already present" || echo "Python 3.13 not found, safe to install"
# Confirm your Ubuntu version (target LTS releases only)
lsb_release -ds
# Check available disk space (source builds need 300+ MB)
df -h /usr/local
If Python 3.13 is already installed, you can skip to the “Work in Python 3.13 Virtual Environments” section unless you need to rebuild with custom flags (like --disable-gil).
Choose Your Python 3.13 Installation Method
Ubuntu 24.04 LTS and 22.04 LTS do not ship Python 3.13 in their repositories. Choose the installation method that best fits your workflow:
| Installation Option | Best For | Trade-offs | Recommendation |
|---|---|---|---|
| Deadsnakes PPA (Ubuntu 24.04/22.04) | Fast installs on supported LTS releases, running Python 3.13 beside the system Python, minimal maintenance | Community-maintained packages without guaranteed security SLAs, monitor CVEs yourself | Recommended for most users. Fast, simple, no compilation required. |
| Compile from Source | Custom prefixes, performance flags, optional --disable-gil free-threaded builds, air-gapped systems | Longer install time (15-30 min), manual updates, requires build dependencies | Use only if you need custom optimization flags or no-GIL testing. |
| Stay on Ubuntu Default Python | Production fleets tied to Canonical packages (Python 3.12 on Ubuntu 24.04 LTS) | No access to Python 3.13 features, slower adoption of new typing and concurrency work | Safest choice for production servers on locked LTS versions. |
| Container or VM isolation | Testing Python 3.13 without impacting host utilities, CI pipelines, or shared servers | Requires container tooling or virtualization overhead | Use for isolated testing environments or multi-tenant systems. |
Never replace /usr/bin/python3 or remove the system interpreter. Use versioned binaries like python3.13 and virtual environments to isolate projects safely.
Understand Support and Compatibility Limits
- Not in Ubuntu 24.04 LTS repositories: Python 3.13 requires the Deadsnakes PPA or source builds on supported LTS releases.
- Deadsnakes PPA is community maintained: Monitor security advisories and be ready to rebuild from source if patched packages lag.
- Ecosystem catch-up period: Popular frameworks like Django 5.x, FastAPI, and pytest support Python 3.13 immediately, while data science libraries like NumPy and Pandas typically lag 2-4 weeks behind major releases. Use
pip checkafter installing dependencies to verify compatibility. - Free-threaded builds are experimental: The
--disable-giloption is for evaluation and performance research, not production use. Library compatibility varies significantly.
Python 3.13 reaches upstream end-of-life in October 2029, per the official release schedule (PEP 719). Plan migrations to Python 3.14 or newer before that date if you need ongoing security updates beyond the five-year support window.
Python 3.13 Pre-Installation Steps
Update System Before Proceeding
Refresh your package lists to ensure dependencies resolve cleanly before adding PPAs or compiling from source.
Open a terminal with Ctrl+Alt+T and run:
sudo apt update
Optionally upgrade existing packages to reduce conflicts during installation:
sudo apt upgrade
Install Python 3.13 on Ubuntu
Use the Deadsnakes PPA for Ubuntu 24.04 LTS and 22.04 LTS, or compile from source when you need custom build flags or air-gapped installation.
Install Python 3.13 via Deadsnakes PPA
Import the PPA and install Python 3.13 packages. Ubuntu 24.04 LTS and 22.04 LTS use the same commands:
Add the Deadsnakes PPA and install packages
Install the repository helper first if your minimal system lacks it:
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.13 python3.13-venv python3.13-dev
If apt returns 404 errors for python3.13, packages have not landed yet. Check availability with apt-cache policy python3.13 and use the source build method until the PPA publishes binaries.
Critical Deadsnakes PPA Disclaimer: The maintainer states there is no guarantee of timely security updates. Production systems must track CVEs and be ready to recompile or sandbox workloads until patches arrive. Use the PPA for development, CI, or testing and rely on Ubuntu’s default Python 3.12 for system tooling.
Monitor the Python Security page and NIST CVE database for Python vulnerabilities. Subscribe to the Python Security Announcements mailing list to receive notifications when security patches are released.
Verify the PPA installation
Verify the installation:
python3.13 --version
Python 3.13.x
Run a quick module test to confirm critical standard library modules compiled correctly:
python3.13 -c "import ssl, sqlite3, bz2; print('Python 3.13 ready on Ubuntu')"
Python 3.13 ready on Ubuntu
Install Additional Python 3.13 Packages (Optional)
Add optional components when you need debugging symbols, dbm bindings, or Tkinter GUI support:
python3.13-dbg for debugging and profiling:
sudo apt install python3.13-dbg
python3.13-gdbm for GNU dbm bindings:
sudo apt install python3.13-gdbm
python3.13-tk for Tkinter GUI applications:
sudo apt install python3.13-tk
There is no
python3.13-fullmeta-package. Install only the components you require, or usepython3-fullto match Ubuntu’s system interpreter (Python 3.12 on Ubuntu 24.04 LTS).
Combine packages in a single command if you need multiple extras:
sudo apt install python3.13-dbg python3.13-gdbm python3.13-tk
Compile Python 3.13 from Source on Ubuntu
Compile Python 3.13 when you need full control over optimization flags, installation prefixes, or the free-threaded build. Source installs live alongside Ubuntu’s system interpreter without overwriting /usr/bin/python3.
Download Python 3.13 Source Tarball
Download the latest 3.13.x release from python.org using wget and extract the archive. The snippet below uses curl to discover the newest patch version automatically:
Install baseline download utilities if they are missing on minimal images:
sudo apt install curl wget ca-certificates
PY313_VERSION="$(curl -s https://www.python.org/ftp/python/ | grep -oE '3\.13\.[0-9]+' | sort -V | tail -1)" || { echo "Failed to fetch Python version"; exit 1; }
[ -z "$PY313_VERSION" ] && { echo "No 3.13.x version found"; exit 1; }
wget "https://www.python.org/ftp/python/${PY313_VERSION}/Python-${PY313_VERSION}.tar.xz" || exit 1
tar -xf Python-${PY313_VERSION}.tar.xz
cd Python-${PY313_VERSION}
If you cannot reach python.org, check the Python.org downloads page for the latest 3.13.x release and substitute that version manually.
Install Build Dependencies
Install the libraries needed for SSL, compression, readline, XML/expat, Tk, and UUID support:
sudo apt install -y build-essential make pkg-config \
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev liblzma-dev uuid-dev \
libgdbm-dev libgdbm-compat-dev libnss3-dev libexpat1-dev libdb-dev \
libncurses5-dev libncursesw5-dev tk-dev libbluetooth-dev
The same dependency set works on Ubuntu 24.04 LTS and 22.04 LTS. Missing packages lead to disabled stdlib modules: expat for XML parsing, ncurses for interactive shells, tkinter for GUI support, and dbm/ssl/bz2 for common libraries.
Configure and Build Python 3.13
Compile with optimization and link-time optimization while installing under /usr/local/python3.13 to keep the system interpreter untouched:
./configure --enable-optimizations --with-lto --with-ensurepip=install --prefix=/usr/local/python3.13
make -j"$(nproc)"
sudo make altinstall
To test the free-threaded preview, append
--disable-gilto the configure command. This build is experimental and intended for benchmarking CPU-bound parallel workloads, not production use. Many third-party libraries expect the GIL and may crash or behave incorrectly without it.
make altinstall prevents overwriting /usr/bin/python3 while adding /usr/local/python3.13/bin/python3.13.
Test Free-Threaded Python 3.13 Build (Optional)
If you compiled with --disable-gil, verify the free-threaded build is working correctly. The binary typically installs as python3.13t (with a ‘t’ suffix indicating the free-threaded variant), and it only exists when you compile with --disable-gil; PPA packages do not ship this binary.
python3.13t --version
Check if the GIL is disabled using CPython’s internal API (available in Python 3.13+):
python3.13t -c "import sys; print('GIL disabled:', not sys._is_gil_enabled())"
GIL disabled: True
sys._is_gil_enabled() is a CPython internal API (underscore-prefixed) introduced in Python 3.13 for testing purposes. It is not part of the stable Python API and may change in future releases. Use this command only for verification during development.
Free-threaded builds benefit CPU-bound code that runs true parallel threads (numerical computing, image processing, data transformation). I/O-bound code (web servers, database queries, file operations) sees little improvement because threads already release the GIL during I/O waits in standard Python. Test your specific workload before committing to no-GIL builds in development environments.
Testing Free-Threaded Performance
To measure if no-GIL actually helps your workload, create a simple multi-threaded benchmark and run it on both standard and free-threaded Python 3.13:
cat > cpu_bound_test.py << 'EOF'
import threading
import time
def cpu_bound_task(n):
total = 0
for i in range(n):
total += i * i
return total
# Run CPU-bound work in 4 threads
start = time.time()
threads = []
for _ in range(4):
t = threading.Thread(target=cpu_bound_task, args=(10000000,))
threads.append(t)
t.start()
for t in threads:
t.join()
elapsed = time.time() - start
print(f"Time: {elapsed:.2f}s")
EOF
# Test on standard Python 3.13
python3.13 cpu_bound_test.py
# Test on free-threaded Python 3.13 (if available)
python3.13t cpu_bound_test.py 2>/dev/null || echo "Free-threaded not installed"
If python3.13t is significantly faster (especially with 4+ threads), your workload benefits from no-GIL. If times are similar, the GIL is not your bottleneck, and you should optimize your algorithm instead.
Popular libraries like NumPy, Pandas, and scikit-learn are gradually adding no-GIL support, but compatibility varies. Always test critical dependencies in a free-threaded environment before deploying. Use the standard GIL-enabled Python 3.13 for production workloads until the ecosystem matures.
Register Libraries and Test the Build
If you installed Python 3.13 to a custom prefix like /usr/local/python3.13, register its shared libraries with the system linker so Python can load them at runtime. If you installed to the system Python prefix or via PPA, skip this step.
# Only needed for custom prefix installations
echo '/usr/local/python3.13/lib' | sudo tee /etc/ld.so.conf.d/python3.13.conf
sudo ldconfig
sudo ln -s /usr/local/python3.13/bin/python3.13 /usr/local/bin/python3.13
ldconfig reads all paths in /etc/ld.so.conf.d/, updates the dynamic linker cache, and enables the OS to find shared libraries (like libpython3.13.so) when you run Python. The symlink in /usr/local/bin adds convenience so python3.13 works from any directory without typing the full path.
Verify the build and confirm critical modules compiled successfully:
python3.13 --version
python3.13 -c "import ssl, sqlite3, bz2; print('Source build is healthy')"
Python 3.13.x Source build is healthy
If the second command fails, reinstall missing -dev packages using the “Install Build Dependencies” section above, rerun ./configure, and rebuild with make -j"$(nproc)" and sudo make altinstall.
Install Pip for Python 3.13
Pip typically installs with the interpreter, but verifying it ensures package management works without touching Ubuntu’s system directories.
Install Pip with python3.13-venv
Keep pip scoped to Python 3.13 instead of the system interpreter. Install the venv module (provides ensurepip), then bootstrap pip inside the interpreter:
sudo apt install python3.13-venv -y
python3.13 -m ensurepip --upgrade || true
python3.13 -m pip --version
ensurepip installs pip inside Python 3.13’s site-packages even if the system interpreter differs. If your build disables ensurepip under externally managed environment rules, create a virtual environment to get pip and keep packages isolated:
python3.13 -m venv ~/venvs/py313-base
source ~/venvs/py313-base/bin/activate
pip --version
Bootstrap Pip with get-pip.py
For air-gapped hosts or custom builds, download the bootstrap script and run it with Python 3.13:
wget https://bootstrap.pypa.io/get-pip.py
python3.13 get-pip.py
rm get-pip.py
This installs pip, setuptools, and wheel together. Download a fresh copy of get-pip.py each time you repeat the process.
Manage Packages with python3.13 -m pip
Call pip through the versioned interpreter to avoid cross-version conflicts:
python3.13 -m pip install package_name
python3.13 -m pip install --upgrade package_name
python3.13 -m pip uninstall package_name
Replace package_name with libraries like numpy, fastapi, or django. For detailed pip workflows, see the Python pip installation guide.
After installing dependencies, verify compatibility and check for conflicts:
python3.13 -m pip check
This command reports broken dependencies, version conflicts, and missing packages that your installed libraries require. Address warnings before committing code that depends on those packages.
Install Python Packages and Verify Compatibility
After pip is working, install packages relevant to your workflow and test compatibility with pip check. Python 3.13 is new. Popular frameworks support it, but data science libraries may lag 2-4 weeks behind release. Always test critical dependencies before deploying.
Test FastAPI installation
Example: Install FastAPI and verify compatibility
python3.13 -m pip install fastapi uvicorn
python3.13 -m pip check
If pip check returns no conflicts, FastAPI is ready for Python 3.13. If warnings appear, review the output and consider using a venv to isolate the installation.
Test Django installation
Example: Install Django and run compatibility tests
python3.13 -m pip install django psycopg2-binary
python3.13 -m pip check
If psycopg2-binary installation fails with a compiler error, the package requires build tools. Install the necessary headers: sudo apt install python3.13-dev, then retry.
Handle data science wheel lag and PEP 668 rules
Note for data science workflows: NumPy, Pandas, and scikit-learn typically release Python 3.13-compatible wheels within 2-4 weeks of Python 3.13 release. If installation fails, check the package’s GitHub releases or PyPI page for version support. Avoid --break-system-packages; use virtual environments for all work.
Ubuntu 23.04 and newer mark the system Python as externally managed under PEP 668. Deadsnakes PPA builds for Python 3.13 carry the same flag to protect apt-managed files, so pip will refuse to write to
/usrwithout a virtual environment. Custom source builds skip PEP 668, but you should still use venvs to isolate projects.Install packages inside a virtual environment instead of bypassing protections. If you compiled Python 3.13 from source, pip installs to its prefix without PEP 668 prompts, but venvs still prevent cross-project conflicts.
Use virtual environments for all project work. Avoid
--break-system-packages; it is only suitable for disposable test systems, not daily development or production machines.
Work in Python 3.13 Virtual Environments
Virtual environments isolate dependencies per project, similar to how Node.js uses node_modules folders or how .NET Core manages NuGet packages per solution. Each environment gets its own interpreter copy and package directory, preventing version conflicts between projects. For expanded guidance, visit the Python virtual environment guide.
Create a Python 3.13 Virtual Environment
Choose a directory for your environments (for example ~/venvs) and create one with Python 3.13:
python3.13 -m venv ~/venvs/py313
Swap ~/venvs/py313 for any path that matches your workflow.
Activate the Virtual Environment
Activate the environment so python and pip resolve to the local interpreter:
source ~/venvs/py313/bin/activate
The shell prompt updates with the environment name, indicating activation.
Deactivate the Virtual Environment
When finished, run:
deactivate
This returns your shell to the system Python context.
Switch Between Python Versions on Ubuntu
Use update-alternatives to control which interpreter runs when you type python while keeping /usr/bin/python3 aligned with Ubuntu defaults. This is similar to how Windows lets you choose default programs for file types, but for command-line tools.
Consider using pyenv for automatic per-directory Python version switching if you manage multiple projects with different interpreter requirements. Pyenv works like nvm (Node Version Manager) for Python, changing versions based on
.python-versionfiles in your project directories. For containerized workflows, use Docker with official Python images to isolate environments completely.
Register Python Versions
Register only versions already installed on your system. Higher priority numbers win when auto-selecting.
# Ubuntu 24.04 LTS (system Python 3.12) with Python 3.13 installed
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.13 8
On Ubuntu 22.04 LTS with the Deadsnakes PPA, register the system interpreter and Python 3.13:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 4
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.13 8
Do not register paths that do not exist. Install the interpreter first via the PPA or source build, then add it to update-alternatives.
Configure the Default Version
Select the default interpreter for the unversioned python command:
sudo update-alternatives --config python
Leave
/usr/bin/python3untouched. Ubuntu utilities and apt rely on the shipped interpreter (Python 3.12 on Ubuntu 24.04 LTS, Python 3.10 on Ubuntu 22.04 LTS).
Troubleshooting Common Python 3.13 Installation Issues
Missing Development Headers During Compilation
If ./configure completes but reports disabled modules for SSL, bz2, sqlite, readline, or other standard library features, critical development headers are missing. Identify which modules were disabled and install the corresponding packages.
Review the configure output to identify disabled modules:
./configure --enable-optimizations --with-ensurepip=install --prefix=/usr/local/python3.13 2>&1 | grep "disabled\|WARNING"
Common missing packages and the modules they enable:
- SSL module disabled → Install
sudo apt install libssl-dev - sqlite3 module disabled → Install
sudo apt install libsqlite3-dev - bz2 module disabled → Install
sudo apt install libbz2-dev - readline module disabled → Install
sudo apt install libreadline-dev - dbm module disabled → Install
sudo apt install libgdbm-dev
After installing the missing packages, rerun ./configure and make -j"$(nproc)" to rebuild with full module support.
Shared Library Linking Errors
If running python3.13 returns error while loading shared libraries: libpython3.13.so.1.0: cannot open shared object file, the linker cannot find the Python library. This occurs when you installed to a custom prefix and forgot to register it with ldconfig.
Locate the library:
find /usr/local -name "libpython3.13.so*"
If the library exists, register its directory and refresh the cache:
echo "/usr/local/python3.13/lib" | sudo tee /etc/ld.so.conf.d/python3.13.conf
sudo ldconfig
Verify the library loads:
python3.13 --version
If the library does not exist, the compilation likely failed. Rerun ./configure, make -j"$(nproc)", and sudo make altinstall in the source directory, then try the ldconfig steps again.
PIP Externally Managed Environment Errors
On Ubuntu 23.04 and newer, pip blocks installs to the system interpreter without a virtual environment. Create a venv instead of bypassing protections:
python3.13 -m venv myproject_env
source myproject_env/bin/activate
pip install package-name
Skip --break-system-packages on any host you care about. Virtual environments isolate dependencies cleanly without risking apt-managed files.
APT Errors After Adding the PPA
If apt errors mention Python after adding the Deadsnakes PPA, ensure you did not modify the system /usr/bin/python3 symlink. It should point to Ubuntu’s default interpreter.
Check the symlink:
ls -la /usr/bin/python3
Restore it if needed:
# Ubuntu 24.04 LTS
sudo ln -sf /usr/bin/python3.12 /usr/bin/python3
# Ubuntu 22.04 LTS
sudo ln -sf /usr/bin/python3.10 /usr/bin/python3
Always call Python 3.13 explicitly with python3.13 instead of altering system links.
C Extension Build Failures During pip install
Some Python packages like psycopg2, cryptography, and numpy require compilation (C extensions). If pip install package-name fails with compiler errors, you need Python development headers. Install them:
sudo apt install python3.13-dev
For Deadsnakes PPA: The package is called python3.13-dev. For source builds: Development headers were built during compilation and live in /usr/local/python3.13/include/python3.13.
After installing headers, retry the package installation:
python3.13 -m pip install psycopg2-binary # or the package that failed
If compilation still fails, the package may not have released Python 3.13 wheels yet. Check the package’s PyPI page or GitHub releases to confirm support before reporting a bug.
If python3.13 -m venv reports that ensurepip is unavailable, install the venv package for PPA builds or confirm you set --with-ensurepip=install for source builds:
sudo apt install python3.13-venv
For source builds missing pip, rerun configure with ensurepip enabled or bootstrap pip via get-pip.py as shown earlier.
Downgrade or Switch Back to Python 3.12
If Python 3.13 introduces compatibility issues with critical packages or projects, you can safely revert to Python 3.12 without affecting the system interpreter. Virtual environments isolate project dependencies, so switching back affects only new projects.
Deactivate Python 3.13 as Default
If you registered Python 3.13 with update-alternatives, change the default back to Python 3.12:
sudo update-alternatives --config python
# Select Python 3.12 from the menu
Rebuild Existing Virtual Environments with Python 3.12
Virtual environments created with Python 3.13 are tied to that interpreter. To downgrade a project, remove the old venv and create a new one with Python 3.12:
# Remove the Python 3.13 venv
rm -rf ~/venvs/py313
# Create a new venv with Python 3.12
python3.12 -m venv ~/venvs/py312
source ~/venvs/py312/bin/activate
pip install -r requirements.txt # If using a requirements file
Virtual environments are isolated, so old ones with Python 3.13 remain on disk until you delete them. Once deleted, you cannot use them. Keep backups of requirements.txt or Pipfile to rebuild environments quickly.
Update Python 3.13 Packages
sudo apt update
sudo apt upgrade
Pending Python 3.13 updates from the PPA appear with other package upgrades.
Remove Python 3.13 Packages
Reminder: Python 3.13 is not the system interpreter on Ubuntu 24.04 LTS or 22.04 LTS. Removing it will not break apt as long as you do not touch
/usr/bin/python3. Verify your release before proceeding.
Uninstall Python 3.13 from the PPA if you no longer need it:
sudo apt remove --purge python3.13 python3.13-venv python3.13-dev
sudo apt autoremove
Confirm your Ubuntu version before removal:
lsb_release -a
Remove the Deadsnakes PPA
Clean up the PPA if you no longer require Python 3.13 packages:
sudo add-apt-repository --remove ppa:deadsnakes/ppa -y
sudo apt update
Clean Up Source-Compiled Installations
Remove source installs and related linker entries if you compiled Python 3.13 manually:
sudo rm -rf /usr/local/python3.13
sudo rm /etc/ld.so.conf.d/python3.13.conf
sudo rm /usr/local/bin/python3.13 2>/dev/null
sudo rm /usr/local/bin/python3.13t 2>/dev/null
sudo ldconfig
Adjust the path if you used a custom prefix such as /opt/python3.13.
Remove update-alternatives Entries
Delete the Python 3.13 alternative if you registered it:
sudo update-alternatives --remove python /usr/bin/python3.13
Verify the remaining entries:
sudo update-alternatives --list python
Alternative: Using pyenv for Automatic Version Switching
For developers managing multiple projects with different Python version requirements, manual version switching with update-alternatives can become tedious. pyenv automatically selects the correct Python version based on a .python-version file in your project directory, similar to nvm (Node Version Manager) for JavaScript.
Install pyenv on Ubuntu
Install pyenv from GitHub (ensure git, curl, and the earlier build dependencies are present):
curl https://pyenv.run | bash
Add pyenv to your shell so shims load on new terminals:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec "$SHELL"
Pin Python 3.13 with pyenv
Install Python 3.13 through pyenv and pin it to a project directory instead of your home directory (to avoid global overrides):
PY313_LATEST="$(pyenv install --list | awk '/ 3\\.13\\.[0-9]+/ {print $1}' | tail -1)"
pyenv install "$PY313_LATEST"
mkdir -p ~/projects/myapp && cd ~/projects/myapp
pyenv local "$PY313_LATEST"
When you enter that directory, pyenv automatically switches to Python 3.13. This approach is ideal for teams with heterogeneous version requirements. However, pyenv adds complexity; for single-version projects or servers, update-alternatives or explicit python3.13 calls are simpler.
Python 3.13 delivers free-threaded builds, typing improvements, and performance refinements with upstream security support through October 2029. The Deadsnakes PPA provides maintenance-free installs on Ubuntu 24.04 LTS and 22.04 LTS, while source compilation enables custom optimization flags and no-GIL testing. Your Ubuntu system now runs the latest interpreter alongside the default Python without conflicts, giving projects access to modern concurrency features and extended support timelines.
Next Steps After Installation
- Create a project virtual environment: Run
python3.13 -m venv ~/myproject, then activate it withsource ~/myproject/bin/activate. See the Python virtual environment guide for workflows. - Install your framework: Use
pip install django,pip install fastapi, or other tools, then test withpip checkfor compatibility warnings. - Monitor security advisories: Subscribe to the Python Security page and NIST CVE database for PPA builds. Python 3.13 reaches upstream end-of-life in October 2029; plan migrations to Python 3.14 or newer before that date.
- Test in production: Use Python 3.13 on development workstations, CI runners, and testing environments first. Migrate production servers only after comprehensive testing confirms stability.
Useful Links
Reference these resources while working with Python 3.13 on Ubuntu:
- Python Official Website: Learn about Python features and downloads.
- Python Documentation: Access the official docs for configuration, libraries, and tutorials.
- PEP 719: Python 3.13 Release Schedule: Review the support timeline through October 2029.
- PEP 703: Making the Global Interpreter Lock Optional in CPython: Understand the free-threaded preview available in Python 3.13 builds.
- What’s New in Python 3.13: Explore new features, deprecations, and performance changes.
- Install Python pip on Ubuntu: Manage pip usage across multiple interpreters safely.
- Create Python Virtual Environments on Ubuntu: Build isolated environments for development and production projects.
- Install Python IDLE on Ubuntu: Set up a GUI interactive development environment for Python 3.13.