Linux

How to Install Python in Ubuntu

Almost every Linux distribution comes with a version of Python included in the default system packages. But on occasion, due to some reasons, you might not find Python installed on an Ubuntu system.

Let’s take a closer look at how you can install Python on Ubuntu, with a brief guide on updating the Python package as well.

How to Check if Python Is Installed on Your System

Python is a powerful, high-level scripting language used by many developers around the globe. The language is ideal for a variety of real-world applications including web development, web scraping, and penetration testing. You can even build a Telegram bot using Python.

To check if Python is installed on your system or not, open up your terminal by pressing Ctrl + Alt + T. Type in “python3” and press Enter.

If you see the following output in your terminal, then you have Python installed on your Ubuntu machine.

Python 3.11.0a7 (main, Apr 20 2022, 17:44:14) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

MAKEUSEOF VIDEO OF THE DAY

This output provides information on the version of Python installed on your system along with the current date and time.

On the other hand, if you see an error that states “bash: python3: command not found,” then sadly your Ubuntu system doesn’t have Python installed.

You can also check for the Python version by simply typing the following command in your terminal:

python3 

The output will give you details on which version of Python is currently installed on your computer.

How to Install Python on Ubuntu

Installing Python on Ubuntu is easy. You can get the latest version of Python from multiple sources. Here are some of the recommended ways to do the same:

Install Python Using APT

APT, or Advanced Package Tool is the default package manager that you will find on Ubuntu. You can download the Python package from the official Ubuntu repository. Here’s how to do it:

  1. Open up your terminal by pressing Ctrl + Alt + T.
  2. Update your local system’s repository list by entering the following command:
    sudo apt update
  3. Download the latest version of Python:
    sudo apt install python3
  4. APT will automatically find the package and install it on your computer.

Use Deadsnakes PPA to Install Python 3 on Ubuntu

If for some reason, you are unable to download the Python package from the official Ubuntu repositories, you can try adding the Deadsnakes PPA to your system repository list. PPAs or Personal Package Archives are repositories that are specially designed for Ubuntu users.

By default, you can’t add PPAs to your system. The “software-properties-common” package provides you with an efficient way to manage and add PPAs on Ubuntu.

  1. Install the above-mentioned package on your system by typing in the following command:
    sudo apt install software-properties-common
  2. Add the official Deadsnakes PPA link to your system’s repository list:
    sudo add-apt-repository ppa:deadsnakes/ppa
  3. Update your system’s package list:
    sudo apt update
  4. Download the latest version of Python from the added PPA:
    sudo apt install python3

Since the Deadsnakes PPA has almost every version of Python in its database, you can install older versions of Python as well. Just replace the package name with the version of Python you want to install on your computer.

sudo apt install python3.2
sudo apt install python3.3
sudo apt install python3.8

Install Python 3 on Ubuntu From Source Code

You can also download and build the latest version of Python from the official Python website. Although compiling the source code might seem a bit daunting to you at first, it’ll become easier once you know the process.

  1. Update your system’s local repository list:
    sudo apt update
  2. Install supporting dependencies on your system with APT:
    sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
  3. Make a new directory to store the Python source files:
    mkdir /python && cd /python
  4. Download the Python source code from the official FTP server:
    wget https:
  5. Extract the TGZ file that you just downloaded:
    tar -xvf Python-3.11.0a7.tgz
  6. You need to perform tests and optimizations before installing Python. This is important as it increases the execution speed of your code by at least 10 percent:
    cd Python-3.11.0a7
    ./configure
  7. Build the package using the MakeFile present in the directory:
    sudo make install


After you’ve implemented these steps, check if Python has been installed on your computer by typing python3 –version in the terminal.

Note that Python modules are managed through PIP. PIP is a package management system used to download and add libraries from the Python Package Index. Installing Python PIP on your system is important if you want to use additional modules in your next Python project.

Updating Python to the Latest Version

First of all, make sure that you have an outdated version of Python installed on your system. You can do this by entering python3 –version in your terminal. Note down the version details.

You can find out what’s the latest version available by searching the internet. A quick Google search on “python latest version number” would suffice. If the two numbers don’t match, then you are probably running an outdated version.

Upgrading to Python’s latest version is easy with Ubuntu’s Advanced Package Tool. If you have installed Python on your system using APT or the Deadsnakes PPA, enter the following command to download the latest Python version:

sudo apt install python3

You can also use the –only-upgrade flag to update your packages.

sudo apt 

For those who have compiled Python from the source on their own, you can head over to the Python FTP and grab a copy of the latest version. You will have to follow the steps all over again to build the package, though.

Running Python in Ubuntu

Python comes preinstalled on almost every Linux system and is available on official distribution repositories as well. If you still don’t have Python installed on your computer, you can easily download it using Ubuntu’s package manager.

The Python language is used in a variety of different sectors, and its applications are enough to demonstrate how powerful it is. Programming languages have now become extremely important because of the growing demand for developers across industries.



programming-jobs

10 Computer Programming Careers and Jobs That Are in High Demand

Read Next



About The Author

Source link

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button