Celeb Glow
updates | March 04, 2026

Updating Python on Ubuntu system

I want to update the Python build on my Linux box, but the only way I know how to do it is uninstalling the current version and installing the new one. My system is already up to date (I updated yesterday). I wanted to know if there is a way to update a specific program from the command line, like sudo apt-get update <program-name>. I know this command doesn't exist, but I'm hoping something equivalent does.

1

10 Answers

As others already noted, bare sudo apt-get install package will install latest available version, replacing the older one if needed.

But with some software (among which is Python) the situation is somewhat different. Some major, very- and incompatibly-different versions get their own packages. For instance, Python 2.6, Python 2.7, Python 3.1 all live in separate packages on Ubuntu.

Of particular importance is the fact that one of Ubuntu policies is to extensively use Python for writing end-user software. So in fact, fairly large part of the system is written in Python. At the moment, the code runs on Python 2.6 — so this version is the default upon installation; and the code won't easily run on, say, Python 2.7 — because incompatibilities exist. To switch the system to Python 2.7 there needs to be done a piece of work, consisting of updating and re-testing all the scripts. This can't be done easily; that is, you can't just "switch" your system to Python 2.7 and delete the older version.

But. If you don't care about fancy gears of your system and just need newer Python — see no obstacles. Go and sudo apt-get install python3 and code for 3.x Python bravely; just remember to launch your scripts with python3 and use #!/usr/bin/env python3 shebang line.


Upd: I keep seeing this upvoted; notice that this is a 9-year old answer, things have changed.


What to learn next

From a superuser perspective (not Python developer's), the next things I'd suggest learning to use:

  • pip/pip3/python3 -m pip — this is the npm for Python. Quick tip: try pip3 install --user howdoi (may need to apt install python3-setuptools python3-pip once, before that works). Then for example, howdoi --all compile python3 ubuntu.

  • The virtualenv tool. It's 100% developer-oriented, but you'll likely need to use it (perhaps underneath a few wrappers, such as tox) to work with people's source packages.
    Ruby's bundler or Cabal sandbox may be familiar analogues.

  • The conda tool — which is a totally separate python package repository and installer (think: fork of PyPi).

There's humongous variety of tools in the Python ecosystem in 2020. At the very least, make yourself comfortable with pip before going deeper.

Basic pitfalls

For the brave but unwary, a few classic pitfalls when trying to manually set up a newer CPython on Ubuntu.

  • Leave /usr alone; you can look but you don't touch. Leave it to dpkg, save yourself some confusion. You have the whole /usr/local at your disposal:

    sudo chown -R `whoami` /usr/local
    pip3 install --prefix=/usr/local pydf
  • Compiling CPython from source is well-explained on the web; just don't forget your /usr/local prefix. This is the best way to manually test patches and/or pre-releases (those alpha-, rc- builds) of CPython itself. To wipe built artifacts, you can just rm -rf /usr/local/*; sudo ldconfig.

  • Finding a PPA is decent option too; keep in mind that a PPA is just someone else's private build. Look for credible PPAs with CI/CD running.

4
sudo apt-get install python 3.3.3

this is for python(3.3.3) for different version the corresponding version number should be used.

4
sudo apt-get install python3.6

This installs python 3 in linux along side python 2.To access python 3 enter after you opened the terminal.

python3
6

You're close with thinking of a command like sudo apt-get update (which is an actual command, but doesn't do what you want it to.)

To upgrade Python, and everything else you have installed, just do the command:

sudo apt-get upgrade
3

From our sister site:

Each of these commands updates-by-installing, which should work just fine in many cases, but might not be what you're looking for in a specific case.

If you only want to upgrade a specific package AND only if it is already installed, then use the command:

sudo apt-get install --only-upgrade packagename

In case you are looking to upgrade only minor version of python package like 2.7.11+ t0 2.7.12 then do sudo apt-get install python2.7 should do for you

pyenv may be a good option for you:


In regards to @ulidtko's answer, a possible alternative to replacing the system python altogether may be to use an isolated environment with your desired python version. This is similar to a "virtual environment", but for python itself. I've used this in the past for legacy projects that run on python 2.6, as well as when upgrading from legacy version of python to python3.

2
apt-get install python

I believe this should work. You will need to change 'python' to match the appropriate package name in your repository obviously.

As we all know that Python comes with 3.5 version. So it is very simple to update Python 2.7(which is by default present into Ubuntu 16.04) to Python 3.5.

Follow the following Steps:

  1. Open terminal.
  2. Become root user by using sudo command.
  3. Use the code below to update Python 2.7 to 3.5

    sudo apt-get install python3.5

  4. You will be asked for your permission, then Give option Y.

  5. Wait till complete the process.
  6. clear the screen by using command clear
  7. Check python version by below command.

    python -version

2

In the single case that you are running a LTS version, your python might be behind by a minor version, say 2.7.5 instead of 2.7.10.

One possibility would be to upgrade the system:

  • set prompt=normal in /etc/update-manager/release-upgrades
  • upgrade the system
    • on the command line, you can type sudo do-release-upgrade to make the upgrade manager do its job to upgrade to the latest (=non-LTS) version.
    • the GUI solution uses the Update Manager

As always when upgrading, have a look at the release notes, as the upgrade might break your system in a few cases, see @Gino's comment.

4