Categories: Ubuntu

How to install a specific Python version on Ubuntu

It is often the case that we install a program on our system, and it turns out that it’s the wrong version. This can lead to compatibility and performance issues since it may not communicate with third-party modules properly. Similar is the case with Python, and as vigilant programmers, we must figure out the correct version that we need. Therefore, in this guide, we will show you how to install a specific version of Python on your Ubuntu system.

Python on Ubuntu

Usually, Python comes preinstalled in many Linux distributions. In our case, we have Python3. Start a new Terminal session through the Activities menu or by pressing Ctrl + Alt +T on your keyboard. To be on the safe side of things, you can check whether your distro has Python installed or not by running the following command.

Sponsored
$ python –version

Or, if you are running Python 3 like us, the command below ought to get the job done.

$ python3 –version

You can see in the image that the system is running Python 3.8.5. It is advised to upgrade your version of Python if you are running Python 3.3 or below. Stick around to find out more on which version you should get, as we will discuss that in the final segment of the article.

In the sections below, we will demonstrate how you can install any version of Python on your system, whether be it an updated one or an outdated one.

Installing a specific version of Python

The first step to installing Python is to install the necessary dependencies and packages that are required for its installation. However, to install these dependencies, you must have the multiverse repository enabled. You can enable it by running the command given below.

$ sudo apt-add-repository multiverse

Once that is out of the way, we move on to installing the first dependency. Run the command below to proceed.

$ sudo apt-get install build-essential checkinstall

It should finish downloading and installing in a few moments. Once it is done, move on to the next one by running the command below.

$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

It is a long and complicated command so simply copy-paste it into your Terminal to avoid any typing errors.

Having done that, we move on to downloading Python and installing it. For the sake of showing you how to install a specific version, we will be downgrading our Python from 3.8.5 to Python 2.7.

First, we change the current directory to the Downloads folder where we wish to download the package. This can be done by running the command below.

$ cd ~/Downloads/

The next step is to “wget” the package from the Python website.

$ wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

Sponsored

Click here to access the location from where you can select any version of Python of your liking. All that needs to be amended in the wget command is the link.

Having successfully downloaded a specific version of Python, the final steps are simple and easy. First, we will extract the package through the command below.

$ tar -xvf Python-2.7.12.tgz

You can replace the version number as Python-version.tgz according to your package.

The next steps include opening the Python directory, configuring the files, and installing it. Run the commands below in the given order to proceed.

$ cd Python-2.7.12
$ ./configure
$ make
$ sudo checkinstall

The installation process, while it is straightforward and simple, should take a few minutes to complete. Once it’s done, you can check whether the installation was successful or not by simply running the commands we mentioned at the start.

As you can tell from the image, we have successfully downgraded from Python 3.8.5 to Python 2.7.12. You can do the same for any particular version of your choice.

Why you should install Python 3.5 or later

Now that we have covered the meat of the matter let’s talk about which Python version you should get and why.

Let’s start with the numbers. It makes sense that as time passes by, a utility or programming language progresses in terms of features and performance. Python 2.0 was released in 2000, Python 2.7 in 2010, whereas Python 3.0 was released in 2008, and Python 3.6 in 2016. The latest versions have more tools and libraries at your disposal, so it makes sense to use the later versions. However, it is understandable if you are trying to install an outdated version on purpose if some feature you need was removed later.

Python 2.0 is still used in many Linux systems as the default version. Some companies also use Python 2 for all their work. However, as the technology progresses, more and more companies are moving toward Python3. For instance, Instagram migrated its code-base from Python 2.7 to Python 3 in 2017. Similarly, Facebook is catching up and is upgrading its infrastructure to Python 3.4 and later.

Furthermore, Python 3 is easier to understand and learn for beginners. So if you happen to be just starting off with this programming language, it’s better to leave the veterans to the old ones and start your journey with a fresh and minted version of Python. In short, for those who haven’t already, consider upgrading your Python to version 3.5 or later.

Conclusion

In the modern era of computing, it is pertinent that we keep our systems updated, our software free of viruses, and our utilities upgraded to their latest versions. This way, we can make our daily tasks easier, simpler, and accurate. So being a programmer or developer helps to have the latest version of Python up and running on your system.

Ubuntu Server Admin

Recent Posts

How to Install Google Cloud BigQuery Python client library on Linux

In this article, we will see how to Install Google Cloud BigQuery Python client library…

2 days ago

Wallpaper Contest for Xfce 4.20 open for voting

Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…

2 days ago

Canonical announces the first MicroCloud LTS release

MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…

3 days ago

Join Canonical in Paris at Dell Technologies Forum

Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…

4 days ago

Bringing automation to open source 5G software at Ubuntu Summit 2024

In today’s massive private mobile network (PMN) market, one of the most common approaches to…

5 days ago

Ubuntu Weekly Newsletter Issue 865

Welcome to the Ubuntu Weekly Newsletter, Issue 865 for the week of November 3 –…

6 days ago