How to Install Python 3.8 on Ubuntu 20.04
Choose a different version or distribution
Introduction
Before we begin talking about how to install Python 3.8 on Ubuntu 20.04, let's briefly understand – What is Python?
Guido van Rossum developed Python, an open source object-oriented programming language written in C. It is widely used to create applications and software for various environments and platforms. In fact, it is one of the most widely used programming languages worldwide.
Python 3.8 is a popular programming language known for its simplicity and versatility. Released in October 2019, it offers several new features and improvements, making it a valuable tool for developers. Some notable additions include the walrus operator, allowing assignment within an expression, and improved performance with faster parsing and evaluation of code.
Python 3.8 also brings enhancements to existing modules and libraries, making development more efficient. With its user-friendly syntax and extensive libraries, Python 3.8 is a preferred choice for both beginners and experienced programmers.
In this tutorial, you will install Python 3.8 on Ubuntu 20.04.
Features of Python Programming Language
- Language is simple to understand.
- It is a language that is dynamically typed.
- It is supported on practically every type of infrastructure.
- It supports features that are object-oriented, such as inheritance and polymorphism.
- Due to its extensive standard library support, it may be easily integrated with other languages.
- It is compatible with a large number of GUI Frameworks.
- Compared to other object-oriented programming languages like C++ and Java, it is less difficult.
- Compiling and debugging are relatively simple.
- It features a great Garbage Collector feature for Memory Management.
Prerequisites to Install Python 3.8 on Ubuntu 20.04
- An operating Ubuntu 20.04 server is required.
- You must have sudo or root access to run privileged commands.
- You must have the
apt
orapt-get
utility installed on your server.
How to Install Python 3 on Ubuntu 20.04
Step 1 – Update Your Server
Before you consider installing any new packages, it is advisable to run a system-wide update using the apt update
or apt-get update
command as shown below. All of your packages will be installed in their most recent iterations, lowering the possibility of any broken package errors.
root@localhost:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 https://packages.microsoft.com/repos/edge stable InRelease [7,343 B]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [545 kB]
Ign:7 http://ppa.launchpad.net/oguzhaninan/stacer/ubuntu focal InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,262 kB]
Get:9 https://packages.microsoft.com/repos/edge stable/main amd64 Packages [8,011 B]
Get:10 http://ppa.launchpad.net/micahflee/ppa/ubuntu focal InRelease [17.5 kB]
Step 2 – Install Python 3.8
You can install whatever version of python3 that best suits your requirements, but in this case, we'll use the apt install python3.8 -y
or apt-get install python3.8 -y
command, as shown below, to install the most recent version.
root@localhost:~# apt install python3 -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
python3.8-venv python3.8-doc
The following NEW packages will be installed:
python3.8
0 upgraded, 1 newly installed, 0 to remove and 199 not upgraded.
Need to get 0 B/387 kB of archives.
After this operation, 521 kB of additional disk space will be used.
Selecting previously unselected package python3.8.
(Reading database ... 179216 files and directories currently installed.)
Preparing to unpack .../python3.8_3.8.10-0ubuntu1~20.04.1_amd64.deb ...
Unpacking python3.8 (3.8.10-0ubuntu1~20.04.1) ...
Setting up python3.8 (3.8.10-0ubuntu1~20.04.1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Step 3 – Check Python Version
Using the python3.8 —version
command, you may determine the installed version of Python. As you can see, the number is 3.8.10
.
root@localhost:~# python3 --version
Python 3.8.10
Step 4 – Write your First Python Program
You must now be wondering how we can verify the use of the Python tool. In order to verify, you can create a simple python file and run it. Here's an example of a simple Python program that prints the message hello world
using our favorite nano
editor, we will create a new file called hello.py
and write a print statement to display hello world
, as demonstrated below.
root@localhost:~# nano hello.py
print('Hello World !!')
root@localhost:~# python3 hello.py
Hello World !!
Step 5 – Remove Python 3.8
You might wonder if the python3.8 that we installed before can be removed. Well, I would advise against it because it's likely that some program that depends on this version may be affected. However, if you are certain that you don't need it any longer, you may simply uninstall it by using the apt remove python3.8 -y
or apt-get remove python3.8 -y
command, as shown below.
apt remove python3 -y
or apt-get remove python3 -y
command, even accidentally, as it will remove all the packages related to python3 without your permission. Running this command will have severe consequences for your server. Therefore, practice caution while performing commands, especially if they are on a production server.FAQs to Install Python 3.8 on Ubuntu 20.04
Can I have multiple versions of Python installed on Ubuntu 20.04?
Yes, you can have multiple Python versions installed simultaneously. Use the update-alternatives
command to switch between versions if needed.
How do I set Python 3.8 as the default version on Ubuntu 20.04?
Use the update-alternatives
command to set Python 3.8 as the default. Run: sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
.
Does installing Python 3.8 on Ubuntu 20.04 remove the existing Python version?
No, installing Python 3.8 won't remove the existing Python version. Both can coexist on your system.
What are the benefits of using Python 3.8 over earlier versions?
Python 3.8 brings new features, improved performance, and enhanced syntax. It offers benefits like the walrus operator, faster code execution, and updated libraries.
Can I still use my existing Python scripts after installing Python 3.8?
Yes, your existing Python scripts should work with Python 3.8. However, it's good practice to test them to ensure compatibility.
Are there any known issues or limitations when installing Python 3.8 on Ubuntu 20.04?
While Python 3.8 is generally stable, there might be occasional issues with specific libraries or packages. It's advisable to check the compatibility of your dependencies before upgrading.
How can I update Python packages and libraries after installing Python 3.8?
Use the "pip" package manager to update Python packages. Run pip install --upgrade package_name
to update a specific package, or pip install --upgrade pip
to update pip itself.
Conclusion
We hope this detailed tutorial helped you to install Python 3.8 on Ubuntu 20.04.
If you have any queries, feel free to drop a comment below, and we'll be happy to help.