3 Way to Install Python on Ubuntu

How to Install Python on Ubuntu
Install Python on Ubuntu

Python usually comes pre-installed in Ubuntu, but if it isn’t accessible on your Linux distribution for any reason, you can install Python in Ubuntu in a few steps. Python is required for developers to build various software and websites.

Aside from that, a lot of Ubuntu’s software relies on Python. So you must have it for the OS to function properly. On that topic, let’s get started with Python installation in Ubuntu.

Let’s take a closer look at how to install Python on Ubuntu, as well as a quick approach to updating the Python package.

How to Find Out If Your System Has Already Python Installed

Python is a powerful, high-level scripting language that is utilised by many developers worldwide. The language is well-suited for a wide range of real-world applications, such as web design, web scraping, and penetration testing. Python can even be used to create a Telegram bot.

  • Open your terminal by hitting Ctrl + Alt + T to see if Python is installed on your machine.
  • Type “python3” and hit Enter.

If the command outputs a version number, that shows Python is already installed on Ubuntu.

Press “Ctrl + D” to quit Python’s environment.

This output displays the Python version installed on your system, as well as the current date and time.

If, on the other hand, you receive the error “bash: python3: command not found,” your Ubuntu system does not have Python installed.

You can also search for the Python version on your terminal by executing the following command. The output will tell you which version of Python is presently installed on your machine.

python3 --version

If a previous version of Python is installed, use the command below to update Python to the most recent version on your Linux distribution.

sudo apt --only-upgrade install python3

How To Install Python on Ubuntu

Python is accessible in Ubuntu’s official repository, so installing it on your system is as simple as executing a single command. This is how you do it.

1. Install Python Using APT

The default package manager on Ubuntu is called APT, or Advanced Package Tool. The Python package is available for download from the official Ubuntu repository. This is how you 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

APT will automatically find the package and install it on your computer.

2. Install Python 3 with the Deadsnakes PPA on Ubuntu.

If you are unable to get the Python package from the official Ubuntu repositories for any reason, you can try adding the Deadsnakes PPA to your system repository list. PPAs, or Personal Package Archives, are repositories created specifically for Ubuntu users.

1. Launch the Terminal by pressing “Alt + Ctrl + T” and entering the following command. This is required for managing your distribution and software sources from third-party providers.

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

3. Install Python on Ubuntu From Source Code

The current version of Python can also be downloaded and built from the official Python website. Although generating the source code may appear difficult at first, it will become easier after you understand the procedure.

1. Update your system’s local repository list:

sudo apt update

2. Next, execute the following command to install all the required dependencies for Python development in Ubuntu.

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. Run the command using sudo if you receive a “Permission denied” message.

sudo mkdir /python && cd /python

4. Download the Python source code from the official FTP server:

wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0a7.tgz

5. Extract the TGZ file that you just downloaded:

tar -xvf Python-3.11.0a7.tgz

6. Before installing Python, you must run tests and optimise it. This is significant since it raises the execution speed of your code by at least 10%:

./configure --enable-optimizations

7. Finally, run the command below to build Python on Ubuntu. The process will take between 10 and 15 minutes to finish.

sudo make install

After you’ve completed these instructions, run python3 –version in the terminal to see if Python is installed on your machine.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply