HomeHOWTOSInstall Python 3.11 on Ubuntu 22.04|20.04

Install Python 3.11 on Ubuntu 22.04|20.04

Welcome to our today’s guide on how to Install Python 3.11 on Ubuntu 22.04|20.04. The most recent version of Python, 3.11, has not yet reached final candidate status and is less stable than Python 3.10. However, this version has been released. Because of its straightforward and simple-to-learn syntax, Python, one of the most popular open-source object-oriented programming languages, is so popular.

Python was created by Guido van Rossum, a Dutch programmer. He is now employed by Microsoft, which anticipates greater enhancement and speed in the next version.

Features of Python 3.11

  • Improved trace back error locations. Information for code objects in columns.
  • Other Language Modifications
  • Changes to Other Python Implementations.
  • Updated Modules.
  • Enhanced Modules that are fractions, optimizations, and asyncio.
  • Speedier CPython quicker start-up.

Install Python 3.11 on Ubuntu 22.04|20.04

There are two methods of installing Python 3.11 on Ubuntu 22.04|20.04.

  1. Install Python 3.11 using PPA
  2. Install Python 3.11 manually

Method 1: Install Python 3.11 using PPA

First, install the package software-properties-common. This abstracts APT repositories and includes some useful scripts for managing software applications from third-party vendors, such as PPAs.

sudo apt install -y software-properties-common

To get Python3 up and running, make sure the local package index is up-to-date. Run the following command to update Ubuntu 22.04|20.04

sudo apt update -y
sudo apt upgrade -y

Perform system reboot.

sudo reboot

Now use the command below to add the ppa to your APT package source list.

sudo add-apt-repository -y ppa:deadsnakes/ppa

Run an APT update after the repository has been imported to update your package manager to reflect the newly imported PPA.

sudo apt update

Install Python 3.11 on Ubuntu 22.04|20.04

sudo apt-get install python3.11

Dependency tree.

Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfwupdplugin1 libxmlb1 linux-headers-5.15.0-46-generic linux-hwe-5.15-headers-5.15.0-46 linux-image-5.15.0-46-generic linux-modules-5.15.0-46-generic linux-modules-extra-5.15.0-46-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython3.11-minimal libpython3.11-stdlib python3.11-minimal
Suggested packages:
  python3.11-venv binutils binfmt-support
The following NEW packages will be installed:
  libpython3.11-minimal libpython3.11-stdlib python3.11 python3.11-minimal
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,534 kB of archives.
After this operation, 21.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Verify Python installation:

$ python3.11 --version
Python 3.11.0

Method 2: Install Python 3.11 Manually

The default version available on the Ubuntu system is adequate for most programming tasks. Installing from the source provides the most recent version, customization options, a security patch, and new features.

First, Install Python 3.11’s necessary dependencies.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev pkg-config make -y

Visit Python official download’s page to obtain the latest version.

Install Python 3.11 on Ubuntu 22.04|20.04
Install Python 3.11 on Ubuntu 22.04|20.04

Change to the /tmp directory and use the wget command to download the Python 3.11 beta source file:

$ cd /tmp
$ wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0b1.tgz

Extract Python Archive:

tar -xf Python-3.11.*.tgz

As indicated below, navigate to the extracted directory and execute the ./configure -enable-optimizations command.

$ cd Python-3.11.*/
$ ./configure --enable-optimizations

Output.

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for Python interpreter freezing... ./_bootstrap_python
checking for python3.11... python3.11
checking Python for regen version... Python 3.11.0
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
.......
checking for stdlib extension module _ctypes_test... yes
checking for stdlib extension module xxlimited... yes
checking for stdlib extension module xxlimited_35... yes
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/Setup.bootstrap
config.status: creating Modules/Setup.stdlib
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
configure: creating Modules/Setup.local
configure: creating Makefile

Build Python 3.11 from the source as shown below after the check is finished. Keep in mind to use the -j switch to accelerate the procedure. This indicates how many cores your machine has. The nproc command displays the system cores.

make -j 4

Output.

...............
running build_scripts
copying and adjusting /tmp/Python-3.11.0b1/Tools/scripts/pydoc3 -> build/scripts-3.11
copying and adjusting /tmp/Python-3.11.0b1/Tools/scripts/idle3 -> build/scripts-3.11
copying and adjusting /tmp/Python-3.11.0b1/Tools/scripts/2to3 -> build/scripts-3.11
changing mode of build/scripts-3.11/pydoc3 from 644 to 755
changing mode of build/scripts-3.11/idle3 from 644 to 755
changing mode of build/scripts-3.11/2to3 from 644 to 755
renaming build/scripts-3.11/pydoc3 to build/scripts-3.11/pydoc3.11
renaming build/scripts-3.11/idle3 to build/scripts-3.11/idle3.11
renaming build/scripts-3.11/2to3 to build/scripts-3.11/2to3-3.11
make[1]: Leaving directory '/tmp/Python-3.11.0b1'

Once the build is finished, follow these steps to install Python 3.11 on Ubuntu 22.04|20.04.

sudo make altinstall

Output.

Creating directory /usr/local/share/man/man1
/usr/bin/install -c -m 644 ./Misc/python.man \
	/usr/local/share/man/man1/python3.11.1
if test "xupgrade" != "xno"  ; then \
	case upgrade in \
		upgrade) ensurepip="--altinstall --upgrade" ;; \
		install|*) ensurepip="--altinstall" ;; \
	esac; \
	 ./python -E -m ensurepip \
		$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmp1s5c_uvp
Processing /tmp/tmp1s5c_uvp/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmp1s5c_uvp/pip-22.0.4-py3-none-any.whl
Installing collected packages: setuptools, pip
Successfully installed pip-22.0.4 setuptools-58.1.0

The default Python binary path is kept at /usr/bin/python using the altinstall flag.

Check Python installation:

$ python3.11 --version
Python 3.11.0

Make Python 3.11 the default version:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1

Verify.

$ python --version
Python 3.11.0

Install Python 3.11 Supporting Packages

Several more packages are frequently required for Python applications to function properly. These auxiliary packages include virtualenv, distutils, and python-dev. They must be installed along with your latest Python upgrade.

Run the following command to install:

sudo apt install python3.11-dev python3.11-venv python3.11-distutils python3.11-gdbm python3.11-tk python3.11-lib2to3 -y

Well done on finishing your job!

Conclusion

That’s all, Python 3.11 has been successfully installed on Ubuntu 22.04|20.04.

Read more about Python.

Other guides include:

How To Install Google Chrome on Ubuntu 22.04|20.04

Install LAMP Stack on Ubuntu 22.04|20.04

- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here