How to Install Python 3 in Ubuntu 20.04 / 22.04

How to Install Python 3 in Ubuntu 20.04 / 22.04. Many people have seemingly become disenchanted with Microsoft’s line of products. Whether we’re talking about Windows or its collection of proprietary .NET programming languages, all their best features seem to be hidden behind paywalls.

Fortunately, there’s an open source counterpart for nearly every paid software product (or an opportunity to write your own). Ubuntu Linux and Python are two of the most popular open source properties in their categories (operating system and programming language). If you’re used to using Windows or Mac, migrating to a Linux distribution is challenging.

Where installing software development kits for  NodeJS or Python is straightforward for Windows, this isn’t the case for many Linux Distros. So if you’re new to Ubuntu and you want to start coding  with Python. Please follow this guide for step by step guide how to install Python 3 on Ubuntu 20.04/ 22.04.

What is Python?

Once upon a time, Java was the open source community’s darling. However, as machine learning and AI became expanded as fields in computer sciences, data scientists and developers needed a more accessible functional programming language. This is where Python came in.

All in all, python essentially allows engineers to worry less about syntax and focus more on solving problems. This makes it ideal for Data Science, Machine Learnin , deep learning and artificial intelligence. Since Python supports a variety of programming paradigms (procedural (imperative), object oriented, functional, structured, and reflective), it accommodates different learning styles and approaches to coding. Furthermore, this makes it easier to transfer what you’ve learned from one programming language to Python. All in all, suitable for developers of all levels of experience and expertise.

But how do you install Python 3 in Ubuntu 20.04 or 22.04? At the time of this guide’s creation, Python 3.11.3 was the latest release. As such, the proceeding tutorials use it as an example.

Recommended Python System Specs

In addition to Ubuntu 20.04/ 22.04 you should at least have the following system specs:

  • 2GB of RAM (Minimum)
  • Intel Core i3 or AMD Ryzen 3250u CPU.
  • 2GB of Disk Space.

How to Install Python On Ubuntu Tutorial

In some cases, python may already be installed on your system. Most Ubuntu installations come with Python pre-installed by default. As such, the first thing you must do is ensure that Python isn’t installed.

Check if Python is Installed

The quickest and most surefire way to verify if Python is installed on your system is by checking the Python version. This requires you to run the Terminal application:

  • Click on Activities. This opensa search field.
  • Type Terminal into the search field.
  • Select the Terminal option.

Once the terminal window is launched, verify the Python version by typing:

				
					python3.11 --version
				
			

If the latest version of Python (3.11.3 or greater) isn’t installed on your system, you are confronted by a message similar to this:

However, you may still have a version of Python installed, even if this command doesn’t execute successfully. To specifically check for Python 3, type the following code:

				
					Python3 --version
				
			

Once again, if Python 3 isn’t installed on your system, you should be greeted with an error message. However, if it is, it displays the Python version number. This means you’re all set to use Python on your computer. Although the version of Python that’s currently installed may be outdated. As such, you may still benefit from using the rest of this guide. So whether you don’t have Python installed on your computer or you’re using an outdated version, the next section shows you how to install Python 3 in Ubuntu:

Installing Python on Ubuntu

To successfully follow these instructions, you must first ensure that you have SUDO privileges. Once that’s done you use the apt command line utility to install Python 3 from the Deadsnakes Personal Package Archive (PPA). While you could use Ubuntu’s default repositories, Deadsnakes was specifically made to help users install Python on their computers. It contains the latest releases of Python, including nightly builds.

  • Launch a terminal window.
  • It’s always good practice to ensure your repository lists are up to date. Enter the following command into the terminal screen:
				
					sudo apt update
				
			
  • Hit Enter.
  • Enter the following command into the terminal screen: 
				
					sudo add-apt-repository ppa:deadsnakes/ppa
				
			
  •  You are presented with a wall of text. Read through the text carefully, then hit the Enter key to continue. Ubuntu then take a few moments to install the Deadsnakes PPA.
  • Once that’s done, refresh your repository lists again ( sudo apt update).
  • Next, run the following command:
				
					sudo apt install python3.11
				
			
  • Follow the prompts on the screen, pressing the Y and/or Enter keys when necessary.
  • Once the installation is complete, verify that it was successful by using the python3.11 --version command.

It’s also a good idea to install the python-is-python3 package. It creates a symlink to the default Python command. This makes it easier for developers who have certain scripts or projects that rely on the Python (and not Python3) command. To install python-is-python3, refresh your Ubuntu repository lists and run the following command:

				
					sudo apt-get install python-is-python3 -y
				
			

Please check the Python (3) version by running this command:

				
					python -version
				
			

How to Uninstall Python from Ubuntu

Well, you may decide that you want to uninstall Python or its older versions from your system. Run the following command to check which versions of Python you have on your computer:

				
					ls /usr/bin/python*
				
			

It results in something similar to this:

To remove a specific version of Python 3 along with its configurations, data files, and dependencies, you must run the following command:

				
					sudo apt-get remove python3.[version number]
				
			

Replace [version number] with the version of Python 3 you want to remove. For example:

				
					sudo apt-get remove python3.10
				
			

Of course, you can’t completely remove Python from the latest versions of Ubuntu because they’re so closely linked. However, you still purge and eliminate any Python packages that are unnecessary with the use of the above command. 

How to Install Python 3 in Ubuntu 20.04 / 22.04 Conclusion

The above guide explores How to install Python 3 in Ubuntu 20.04/ 22.04. As this guide mentions, Python may already be installed on your version of Ubuntu. The fact is Ubuntu (particularly Ubuntu-Minimal) uses Python for many of its important features. Thus, it’s not possible to completely separate or remove Python from Ubuntu. Regardless, the installed version of Python may not be the latest and it may not be accessible to you. Although updating or installing the latest version of Python is always a good idea.

So now that you’ve installed it, the next step is to master it. A good place to start (as a beginner) is learning how to compile and run Python applications using a simple Hello World example. Nevertheless, we hope that you’ve found this guide helpful. Please leave a comment down below if you have any questions, corrections, or queries. As always, thank you for reading.

Avatar for Mduduzi Sibisi
Mduduzi Sibisi

Mdu is an Oracle-certified software developer and IT specialist, primarily focused on Object-Oriented programming for Microsoft and Linux-based operating systems. He has over a decade of experience and endeavors to share what he's learned from his time in the industry. He moonlights as a tech writer and has produced content for a plethora of established websites and publications - including this one. He's always open to learning and growing.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x