How to Install Python in Ubuntu Linux (4 Methods)
Generally, Python comes pre-installed in Ubuntu, but if it’s not available on yourLinux distrofor some reason, you can install Python in Ubuntu in a few steps. If you’re a developer,Pythonis essential to build various software and websites. Other than that, a lot of Ubuntu’s software relies on Python, so you must have it for the smooth functioning of the OS. On that note, let’s go ahead and learn how to install Python in Ubuntu.
Install Python in Ubuntu (2022)
In this tutorial, we have included three ways to get Python on Ubuntu. But before that, let’s check if Python is already installed on your system and update it accordingly.
Note: We tested the commands and methods listed below on the latest version, i.e. Ubuntu 22.04 LTS and Ubuntu 20.04.
Check If Python is Already Installed on Ubuntu
Before you install Python in Ubuntu, you should check whether it’s already installed on your system. This allows you to update the existing Python installation without having to install it from scratch again. It should also come in handy if you ever wish to downgrade to a different Python version. With that said, here are the steps to follow.
-
First, open Terminal using the “Alt + Ctrl + T” keyboard shortcut and run the below command. If the command gives an output with the version number, it means you already have Python installed in Ubuntu. To exit Python’s environment, press “Ctrl + D”. In case you get an error message like “Command not found”, you don’t have Python installed. So move to the next method to install it.
-
You can also run the below command tocheck the Python versionon your Ubuntu installation.
-
If an older version of Python is installed, run the below command toupdate Pythonto the latest version on your Linux distro.
Install Python in Ubuntu from Official Repository
Python is available in Ubuntu’s official repository, so you don’t have to do much other than execute a simple command to seamlessly install it on your system. Here is how to do it.
-
Open Terminal in Ubuntu and run the below command toupdate all the packagesand repositories.
-
Next,install Pythonin Ubuntu by running the below command. This will automatically install Python on your machine.
Install Python in Ubuntu from Deadsnakes PPA
Apart from the official repository, you can also pull newer versions of Python fromDeadsnakes PPA, which is popular for hosting new and old versions of Python. If Ubuntu’s official repository (APT) was unable to install Python on your system, this should certainly work. Here are the steps to follow.
-
Fire up the Terminal using the “Alt + Ctrl + T” shortcut andrun the below command. This is needed to manage your distribution and software sources from independent vendors.
-
Next, run the below command toadd Deadsnakes PPAto Ubuntu’s repository. When prompted, press Enter to continue.
-
Now, update the package list and run the next command toinstall Python.
-
You can also choose toinstall a specific version(old or new) of Python from Deadsnakes PPA. It also hosts nightly builds of Python (experimental), so you can install them as well. Run the commands in the following fashion:
or
Build Python in Ubuntu from the Source Code
If you wish to go the extra mile and build Python directly in Ubuntu from the source code, you can do so. But bear in mind, it’s a slightly lengthier process and might require more than 15 minutes to compile Python, depending on your hardware specs. Here are the steps you need to follow.
-
First, open the Terminal and run the below command toupdate the packages.
-
After that, run the next command to install therequired dependenciesto build Python in Ubuntu.
-
Next,create a “python” folderand move to the said folder. If you get a “Permission denied” error, run the command withsudo.
-
Following that, usewgettodownloadthe latest version of Python from theofficial website. Here, I am downloading Python 3.12.0a1.
-
Now,extractthe downloaded file using thetarcommand and move to the extracted folder.
-
After that, run the below command toturn on optimizationsbefore building Python in Ubuntu. This will reduce the time for Python compilation.
-
Finally, execute the below command tobuild Python in Ubuntu. This will take anywhere between 10 to 15 minutes to complete the process.
-
Once it’s done, run thepython3 –versioncommand to check the Python version number. And you are done.
Install or Update Python in Ubuntu in 4 Easy Ways
So this is how you can install Python in Ubuntu Linux. If you didn’t choose a minimal setup during installation, then you likely have Python installed on your system. Then, you only need to check the version and update the existing Python installation. However, if you don’t have Python installed, you can follow one of the three methods described above to install it right away. Anyway, that is all from us. If you want torun Android apps in Linuxwithout an emulator, follow our guide for detailed instructions. Finally, if you have any questions, let us know in the comment section below.
Arjun Sha
Passionate about Windows, ChromeOS, Android, security and privacy issues. Have a penchant to solve everyday computing problems.
Add new comment
Name
Email ID
Δ
01
02
03
04
05