Python is popular programming and scripting language which is used in different cases and applications. Python is cross-platform and can be used in different platforms, and operating systems. Python3 is the latest version and can be installed on Ubuntu easily. In this tutorial, we examine different methods to install Python3 on all Ubuntu distributions.
Check Python3 Installation
Before starting to install Python3 we can check the Python3 installation by using the
-V option. The -V option is used to check the installed Python version.
$ python3 -V
If Python3 is not installed the following message is displayed on the terminal.
Command 'python' not found, did you mean: command 'python3' from deb python3 command 'python' from deb python-is-python3
Install Python3 Using apt Package Manager
apt is a standard package manager for the Ubuntu distributions. The apt command can be used to install Python3 easily with little effort. First, we update the apt package repository information to get the latest version information of the Python3.
$ apt update
sudo apt install command is used to install Python3 like below. The sudo command is used to get root privileges as package management requires root privileges.
$ sudo apt install python3
Install Python3 Using Source Code
Python can be installed by using its source code. This method is the dirty way but has some advantages. The latest source code can be used to install the latest version of Python3. Also, modifications can be done by changing the source code, etc. Let’s start Python3 installation via the source code.
$ apt update
In this step, we install the required libraries that are used to compile the Python3 source code.
$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Download the latest Python3 source code via the following download page.
$ wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz
Extract the source code with the
tar command below.
$ tar -xf Python-3.10.4.tgz
Then enter the extracted source file directory with the cd command.
$ cd Python-3.10.4/
Prepare for the compile operating with the
$ ./configure --enable-optimizations
If there is an error like “configure: error: no acceptable C compiler found in $PATH” we should install the
gcc compiler with the following command.
$ sudo apt install gcc
The last step is the compilation and installation of the Python3 with the
make install command.
$ sudo make install
Check Installed Python Version
The installed Python3 version can be displayed with the
-V option like below.
$ python3 -V
From the output, we can see that the version is 3.10.4 in detail.