How to install the latest Python version in Ubuntu

Use your little hands to make a fortune and give it a like!

Python is the fastest growing major general-purpose programming language. There are many reasons for this, such as its readability and flexibility, ease of learning and use, reliability and efficiency.

There are two major versions of Python in use today – 2 and 3 (Python's present and future); the former does not see new major versions, while the latter is under active development and has had many stable releases over the past few years. The latest stable version of Python 3 is version 3.11.

On newer Ubuntu versions, Python 3.10 or Python 3.8 comes preinstalled, while older Ubuntu versions do not.

In this article, we will explain how to use deadsnakes PPA to install the latest Python 3.11 version on all Ubuntu versions through apt package manager.

To install the latest version of Python from source on all major Linux distributions, check out this guide:

Install

To install the latest Python 3.11 version, you can use the "deadsnakes" team PPA, which contains the latest Python version packaged for Ubuntu.

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update
$ sudo apt install python3.11

If you want to install a specific Python version or multiple versions of Python on your Ubuntu system, just run the following command and enter the Python version number as shown.

$ sudo apt install python3.10
$ sudo apt install python3.9
$ sudo apt install python3.8
$ sudo apt install python3.7
$ sudo apt install python3.6

To view a list of all Python binaries installed on your system, run the following ls command.

$ ls -l /usr/bin/python*

List Python binaries

lrwxrwxrwx 1 root root      10 Apr 22  2022 /usr/bin/python3 -> python3.10
-rwxr-xr-x 1 root root 5901416 Apr  2  2022 /usr/bin/python3.10
-rwxr-xr-x 1 root root 6705016 Oct 24 15:56 /usr/bin/python3.11
-rwxr-xr-x 1 root root     960 Dec 23  2020 /usr/bin/python3-futurize
-rwxr-xr-x 1 root root     964 Dec 23  2020 /usr/bin/python3-pasteurize

Judging from the output of the screenshot above, the default Python version of the test system is 3.10. You can also use the following command to check the Python version.

$ python -V

Python 3.10.4

To use Python 11, call the following command.

$ python3.11

Access Python Shell

Python 3.11.0 (main, Oct 24 2022, 19:56:13) [GCC 11.2.0] on linux
Type "help""copyright""credits" or "license" for more information.
>>> print ("TecMint #1 Linux Blog");
TecMint #1 Linux Blog
>>> quit()

To exit the Python interpreter, type the following command and press Enter.

quit()
OR
exit()

Set default version

If you have multiple versions of Python installed on your Ubuntu system and you only want to set one version as the default, then you need to perform some extra steps as shown.

$ python3 --version
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
$ sudo update-alternatives --config python3
$ python3 --version
alt

that's all! In this short article, we explain how to install Python 3.11 in Ubuntu through apt package manager.

本文由 mdnice 多平台发布

Guess you like

Origin blog.csdn.net/swindler_ice/article/details/132417881