Python, a versatile and popular general-purpose programming language can easily be installed on Ubuntu via multiple methods. Whether you’re building an advanced program or creating a simple task in Python, you’ll need Python installed to use it. With Python, you can do almost anything like writing simple or advanced scripts, building and programming robots, complicated machinery, developing websites, and many more. Python also lets you work quickly and integrates systems more efficiently. The latest versions of Python come with many new features including, assignment expression — which assigns values to variables as part of a larger expression, position-only parameters, f-strings support, and many more. There are many ways to install Python on Ubuntu. Below are two methods one can use to install python on Ubuntu Linux.
How to install Python from Ubuntu repositories
The quickest way to install Python on Ubuntu is to install it from Ubuntu’s default repositories. Python is available in Ubuntu default repositories so all one needs to do is simply run the apt-get command to install it. However, the versions of Python in Ubuntu repositories may not necessarily be the latest. Ubuntu repositories do not always have the latest software builds. To install Python from the Ubuntu repository, run the commands below After installing Python above, run the commands below to see which versions of Python are installed. That should output a similar line as below with the version of Python installed. As you can see, version 2.7.18 is the current build of Python available in Ubuntu.
How to install Python from source code on Ubuntu
If you want to install the latest versions of Python on Ubuntu, you will want to build it from the source code. Installing Python from source code gives you control over which version to install. Before installing Python from its source code, you must first install some required packages that are needed to build Python from the source. To get these packages installed, run the commands below: After installing the above packages, go and download the latest release’s source code from the Python download page using the following wget command. At the time of writing this post, 3.9.7 is the latest Python version. If you find a later version on the site, you can download it instead. After downloading the package, run the commands below extract the file, and install. Next start the building process using the make command. Replace #4 with the number of CPU cores on your system for faster build time. My machine has 4 CPU cores, so I use the make command with the -j 4 option. Do not use the standard make install as it will overwrite the default system with the python3 binary. After that, Python version 3.9 should be installed and ready to use. To test if the latest version of Python (which is 3.9) is installed and ready to use, run the commands below You should see an output similar to the one below: That’s how you install Python from its source Conclusion: This post showed you how to install Python on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.