Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk11 min

How to Change the Default Python Version on Ubuntu (Safely)

Use a project virtual environment or pyenv to select Python versions on Ubuntu while keeping the apt-managed system interpreter intact. This guide explains python-is-python3, externally managed pip errors, update-alternatives risks, release checks, verification, and rollback.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To use Python 3.11, 3.12, or another interpreter on Ubuntu, do not replace Ubuntu’s managed /usr/bin/python3. Install the version you need, create a virtual environment with that interpreter, and activate it for the project. If you only want python to mean Python 3, install python-is-python3. A machine-wide change to the system interpreter is an administrative decision because Ubuntu system tools depend on the packaged default.

What “default Python” means on Ubuntu

The question “How do I change the default Python version on Ubuntu?” can describe three different changes. Choosing the right scope prevents broken package management and makes your setup reproducible.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Project default

A project default is the interpreter selected inside a virtual environment such as project/.venv. It affects only commands run while that environment is active. This is the recommended approach for applications, coursework, data analysis, and development because each project can use its own Python version and dependencies.

User shell default

A user default changes what your shell resolves when you type a command. An activated virtual environment, a shell alias, PATH ordering, or pyenv can make one Python version appear first for your account without modifying Ubuntu’s system files.

System default

The system default is the interpreter reached through Ubuntu’s managed path, normally /usr/bin/python3. Ubuntu states that this path is a symbolic link to the release’s current default Python interpreter. Distribution scripts and packages may rely on that relationship. Ubuntu explicitly warns not to remove the default python3 package because doing so can break system tooling.

For that reason, changing the system link is not routine project setup. Prefer a virtual environment, pyenv, an explicit versioned command such as python3.12, or a user-level shell setting.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Identify your Ubuntu release and installed interpreters first

Python versions available as Ubuntu packages differ by release. A command that works on Ubuntu 22.04 may not select the right interpreter on Ubuntu 24.04 or a later release. Record the release before installing anything:

lsb_release -a
cat /etc/os-release

List the versioned Python executables already present:

command -v python3
ls -1 /usr/bin/python3*

Check each candidate directly rather than assuming a version exists:

python3 --version
python3.10 --version 2>/dev/null || true
python3.11 --version 2>/dev/null || true
python3.12 --version 2>/dev/null || true

Ubuntu publishes a release-by-release table of available Python 3 packages and the python3-defaults version. Use that table, together with your release information, when you need a version that is not already installed. Do not copy a package name from a different Ubuntu release without checking its repositories.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safest method: choose Python for one project with a virtual environment

A virtual environment gives a project its own interpreter entry points and site-packages directory while leaving Ubuntu’s system Python untouched. The following example uses Python 3.12; substitute the versioned executable that actually exists on your machine.

1. Install the venv support and a complete Python installation

sudo apt update
sudo apt install python3-venv python3-full

python3-venv supplies the standard-library virtual-environment module. python3-full supplies a fuller interpreter installation useful for development. If you need a different Ubuntu-packaged version, install the matching packages available for your release and verify the executable name afterward.

2. Create the environment with the desired interpreter

mkdir -p ~/projects/example
cd ~/projects/example
python3.12 -m venv .venv

The command that creates the environment determines its interpreter. If you run python3 -m venv .venv, the environment follows whichever interpreter python3 currently denotes. To request Python 3.11 or 3.12 specifically, invoke python3.11 or python3.12 explicitly.

3. Activate it

source .venv/bin/activate

Your prompt normally gains a (.venv) prefix. Activation adjusts PATH for the current shell; it does not alter /usr/bin/python3 for the rest of the machine.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Verify the executable and version

which python3
python3 --version
python --version
python -m pip --version

which python3 should show a path under your project, such as /home/you/projects/example/.venv/bin/python3. Inside an active environment, PEP 394 recommends that python refer to that environment’s interpreter and be consistently available. Using python -m pip ensures pip belongs to the same interpreter instead of another copy on PATH.

5. Install project dependencies and record the environment

python -m pip install --upgrade pip
python -m pip install <package-name>
python -m pip freeze > requirements.txt

Replace <package-name> with a real dependency for your application. Keep .venv out of source control; commit the requirements file or another dependency lock file instead.

6. Leave the environment when finished

deactivate

Deactivation restores the shell’s previous PATH. Re-enter the project directory and run source .venv/bin/activate whenever you need that interpreter again.

Make python invoke Python 3

Some Ubuntu installations provide python3 but no unversioned python command. If your only requirement is that typing python invokes Ubuntu’s Python 3, install the distribution package that creates the link:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt install python-is-python3

This supplies a /usr/bin/python link to /usr/bin/python3. It does not select an arbitrary Python release, and it does not replace the release’s system default. Confirm the result:

python --version
command -v python
readlink -f "$(command -v python)"

In an active virtual environment, the environment’s python should take precedence. That behavior is preferable to a global alias because scripts and tools launched inside the environment receive the interpreter selected for that project.

Use several Python versions with pyenv

When multiple projects require different Python releases, pyenv provides user-level selection without repointing Ubuntu’s system Python. Ubuntu’s developer guidance describes pyenv as a way to change a global Python version without interfering with the system interpreter.

Why pyenv fits multi-project work

  • Each project can select a different interpreter.
  • Your account’s selected version is separate from Ubuntu’s apt-managed files.
  • You can keep the distribution Python available for system tools.
  • Changing a project selection is easier to roll back than changing a system symlink.

Install pyenv by following its current upstream instructions and then configure its initialization in both ~/.bashrc and ~/.profile. Ubuntu specifically recommends configuring both files so interactive shells and login shells see the same selection. Start a new login session after editing them, or load the files in the current shell according to the pyenv instructions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Once pyenv is installed, the normal workflow is conceptually:

pyenv install <available-version>
cd ~/projects/example
pyenv local <available-version>
python --version
command -v python

The exact version must be one supported by your pyenv installation and build dependencies. pyenv local writes a project-level selection, normally in a .python-version file. Use pyenv global only when you intentionally want a default for your account. Keep Ubuntu’s python3 untouched even when pyenv supplies the python command in your shell.

Changing the shell’s default without touching system files

For a temporary choice, call the versioned executable directly:

python3.11 -m venv .venv311
python3.12 -m venv .venv312

For a project, activation is more reliable than a permanent alias because it changes both python and package-script resolution. If you do use a shell alias for an interactive convenience, remember that aliases are not normally applied to non-interactive scripts, cron jobs, or services. A script should use an explicit interpreter, a virtual-environment shebang, or a controlled service configuration instead of relying on your personal shell startup files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PATH edits can also change which executable a user shell finds first, but they can make diagnostics harder when several installations coexist. After any PATH change, verify with command -v python, command -v python3, and readlink -f rather than trusting the prompt.

Why update-alternatives needs caution

update-alternatives is a generic Debian/Ubuntu utility for maintaining symbolic links that select a command implementation. Community instructions sometimes use it to register multiple python3 binaries and choose one. The mechanism is real, but that does not make changing the python3 link universally safe.

Ubuntu’s own setup guidance emphasizes preserving the distribution-managed python3 installation. Distribution utilities may expect the release’s packaged default, and an alternative interpreter can lack modules or behavior those tools require. A system-wide alternatives change also affects every user and service, making rollback and diagnosis more difficult.

Use this decision order instead:

  1. Use a virtual environment for an application or project.
  2. Use pyenv when several user projects need different releases.
  3. Run an explicit executable such as python3.12 for a one-off command.
  4. Use a user-level shell setting only when the scope is clearly interactive and personal.
  5. Consider a system-wide alternatives change only as a documented administrative change, after confirming the release’s package expectations and preparing a rollback.

Never remove Ubuntu’s python3 package to force a different version. If a system tool stops working after an interpreter-link change, restore the distribution-managed packages and links using apt and your recorded release information before troubleshooting the application itself.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fixing pip’s “externally managed environment” error

Ubuntu may prevent pip from installing into the system interpreter and show an externally-managed-environment error. This protection exists because apt owns the system installation; mixing arbitrary pip files into it can create conflicts that apt cannot safely manage.

Install a Debian-packaged module with apt

If the module is available in Ubuntu’s repositories and you want it managed with the operating system, install its python3-... package:

sudo apt update
sudo apt install python3-<module-name>

Package names and available versions depend on your Ubuntu release.

Install application dependencies in a virtual environment

python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install <package-name>

Because pip now targets .venv, it does not modify the apt-managed interpreter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install a standalone Python application with pipx

For command-line applications rather than import libraries, pipx creates an isolated environment and exposes the application command. Install pipx using the method supported by your Ubuntu release, then install the application into its isolated environment. This avoids placing application files in the system site-packages directory.

Why not use --break-system-packages routinely?

pip offers --break-system-packages to override the protection, but the option deliberately bypasses Ubuntu’s safeguard. It should be reserved for a consciously managed exception with a recovery plan, not used as the normal way to install project dependencies.

Verification checklist after changing your effective default

Run these commands in the same shell where the problem occurs:

python3 --version
command -v python3
readlink -f "$(command -v python3)"
python --version 2>/dev/null || true

Inside a virtual environment, also run:

which python3
python -c 'import sys; print(sys.executable); print(sys.version)'
python -m pip --version

The executable path should be under the project directory, and pip’s path should point into the same environment. If the prompt shows an environment name but sys.executable points to /usr/bin, activation is incomplete or another shell configuration has overridden PATH.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When asking for help, include the Ubuntu release from lsb_release -a or /etc/os-release, the exact command used to create the environment, and the output of command -v. Python version names alone are not enough to diagnose a release-specific package problem.

Choosing the right approach

Approach System files changed? Scope Multiple versions Package isolation Rollback difficulty apt compatibility
Virtual environment No One project Yes, one environment per version Strong Easy: delete the environment Excellent; system Python remains managed
pyenv No, when configured for the user User or project Yes Strong when combined with environments Easy to moderate Excellent for the system interpreter
python-is-python3 Creates the packaged /usr/bin/python link Whole machine’s unversioned command No None by itself Easy through apt Designed for Ubuntu’s packaged Python 3
Explicit python3.x command No One command or script Yes None unless used with venv Easy Excellent
Shell alias or PATH adjustment No One user and selected shells Possible None by itself Easy but configuration-dependent Usually safe if system paths are untouched
update-alternatives for python3 Yes, changes command-link selection Whole machine Yes None by itself Moderate to difficult Risky; distribution tools may expect the packaged default
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common problems

python3.12: command not found

The interpreter is not installed under that name, or your Ubuntu release does not provide it through the enabled repositories. Check ls -1 /usr/bin/python3*, confirm the release, and install only a package version supported for that release. If you already have another version, create the environment with that executable instead of copying the example unchanged.

The environment was created with the wrong Python version

Inspect it with python -c 'import sys; print(sys.executable); print(sys.version)'. A virtual environment does not change its base interpreter when you later change PATH. Remove and recreate the environment with the desired executable:

deactivate 2>/dev/null || true
rm -rf .venv
python3.12 -m venv .venv
source .venv/bin/activate

Reinstall dependencies from your requirements file after recreating it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

python still resolves to an unexpected executable

Check both the command location and shell cache:

command -v python
command -v python3
type -a python
type -a python3

If you changed PATH or an alias, start a new shell or clear the shell’s command hash using the mechanism provided by your shell. Then verify again. Inside a venv, activate it after entering the project directory.

pip installs into the wrong location

Do not run a bare pip when several interpreters exist. Activate the intended environment and use python -m pip. Compare python -c 'import sys; print(sys.executable)' with python -m pip --version; both should reference the same environment.

A system command fails after changing Python links

Stop treating the issue as a project configuration problem. System scripts may depend on Ubuntu’s packaged interpreter and modules. Undo the link or alternatives change, restore the apt-managed python3 packages for your release, and then use a venv or pyenv for the application that needed another version. Do not delete /usr/bin/python3 or the python3 package.

A scheduled job or service uses a different Python

Cron, systemd, and other non-interactive launchers do not necessarily read your interactive shell startup files. Use the absolute path to the project environment’s interpreter, for example /home/you/projects/example/.venv/bin/python, in the job or service definition. Verify that the service account can read the project and environment, then log sys.executable during troubleshooting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safe rollback plan

  • For a project change, deactivate and remove only that project’s .venv, then recreate it with the required version.
  • For pyenv, remove or change the project’s local version selection and leave Ubuntu’s system Python alone.
  • For python-is-python3, remove the package with apt only if you no longer want the unversioned command; this is separate from the packaged python3 interpreter.
  • For aliases or PATH edits, remove the corresponding shell-startup line and open a new shell.
  • For an alternatives or symlink experiment, restore Ubuntu’s release-managed selection before attempting application repairs, and document every command used so another administrator can reproduce the rollback.

The durable pattern is simple: let Ubuntu keep its release default, select another version at the project or user level, and verify the actual executable path every time the result matters.

Frequently Asked Questions

Can I make Python 3.12 the default only for one directory?

Yes. Create a virtual environment in that project with python3.12 -m venv .venv and activate it when working there. The selection remains local to the project and does not change Ubuntu’s system interpreter.

Do I need to change /usr/bin/python3 to run Python 3.11?

No. Invoke the installed version directly, such as python3.11, or use it to create a virtual environment. Repointing the system link can disrupt Ubuntu tools.

What should I do when Ubuntu does not offer the Python version I need?

First confirm the Ubuntu release and available packages. For user development across several versions, use a version manager such as pyenv rather than replacing the apt-managed interpreter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.