4 C
New York
Sunday, January 19, 2025

How one can Set up Python on Ubuntu?


Python is without doubt one of the most generally used programming languages, identified for its simplicity and suppleness.

Python 3 is the latest model, providing enhancements in efficiency, safety updates, and new options that make it extra appropriate with fashionable libraries and instruments. 

If you wish to set up Python on Ubuntu, whether or not it’s Ubuntu 20.04 or 22.04, this handbook will present you easy methods to do it effectively.

Conditions for Set up

Prerequisites for Installation

Earlier than you proceed with putting in Python 3, make sure that your system meets the next situations:

  • Your system must be operating Ubuntu 20.04 or Ubuntu 22.04.
  • You have to have a consumer account with root privileges.
  • It’s best to have entry to the terminal (Ctrl+Alt+T).

Checking if Python is Already Put in on Ubuntu

Checking if Python is Already Installed on Ubuntu

Earlier than putting in Python on Ubuntu, it’s a good suggestion to test if Python 3 is put in in your machine. Open the terminal and sort the next command:

bash

Copy code

python3

  • If Python 3 is put in, you’ll see its model data and extra particulars like copyright and license.
  • When you get an error message like “bash: python3: command not discovered,” it means Python shouldn’t be put in.

Strategies to Set up Python on Ubuntu

There are a number of methods you possibly can set up Python 3 on Ubuntu. Beneath are the three fundamental strategies to contemplate:

1. Set up Python Utilizing APT

This technique is probably the most simple, utilizing the APT package deal supervisor to get Python from the default Ubuntu repositories.

Nonetheless, do not forget that this won’t all the time present the most recent Python model.

Steps to put in Python by way of APT:

  • Replace Bundle Repositories
    To get the most recent out there packages, run the next command:
    bash
    Copy code
    sudo apt replace
  • Set up Python 3
    As soon as the repositories are up to date, run this command to set up Python on Ubuntu:
    bash
    Copy code
    sudo apt set up python3
  • Confirm the Set up
    After the set up completes, test the put in Python model by operating:
    bash
    Copy code
    python3 –model

2. Putting in Python from Supply Code

When you choose to put in the most recent Python model, you possibly can obtain the supply code from the official Python web site and compile it manually.

This course of is extra complicated however ensures you get the latest model.

Steps to put in Python from supply:

  • Replace Native Repositories
    First, replace the package deal repositories:
    bash
    Copy code
    sudo apt replace
  • Set up Required Dependencies
    To compile Python from supply, you’ll want to put in some extra software program:
    bash
    Copy code
    sudo apt set up build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
  • Obtain the Python Supply Code
    Change to the /tmp listing the place you’ll obtain the supply code:
    bash
    Copy code
    cd /tmp

Go to the official Python web site and select the model you need. Copy the obtain hyperlink and use wget to obtain it. For instance:
bash
Copy code
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz

  • Extract the Recordsdata
    After downloading, extract the compressed file:
    bash
    Copy code
    tar -xf Python-3.12.1.tgz
  • Configure and Optimize Python
    Enter the extracted listing and configure the construct course of:
    bash
    Copy code
    cd Python-3.12.1

./configure –enable-optimizations

This step optimizes Python for higher efficiency, dashing up code execution.

  • Set up Python
    Now, compile and set up Python with:
    bash
    Copy code
    sudo make set up

If you wish to set up a secondary model alongside an present one, use:
bash
Copy code
sudo make altinstall

  • Verify Python Model
    To substantiate the set up was profitable, run:
    bash
    Copy code
    python3 –model

3. Putting in Python from a PPA

If you wish to set up a newer model of Python, you should utilize the Deadsnakes PPA. This technique provides a third-party repository to get newer variations of Python.

Steps to put in Python from PPA:

  • Replace Repositories
    Begin by updating the native repository checklist:
    bash
    Copy code
    sudo apt replace
  • Set up Software program Properties
    Set up the software-properties-common package deal to handle extra repositories:
    bash
    Copy code
    sudo apt set up software-properties-common
  • Add the Deadsnakes PPA
    Add the Deadsnakes repository to your system:
    bash
    Copy code
    sudo add-apt-repository ppa:deadsnakes/ppa

After including the PPA, replace your repositories:
bash
Copy code
sudo apt replace

  • Set up Python 3
    Now you possibly can set up Python 3.12 (or some other model out there within the PPA):
    bash
    Copy code
    sudo apt set up python3.12
  • Confirm the Set up
    Verify the Python model with:
    bash
    Copy code
    python3 –model

Conclusion

Following considered one of these strategies, it is best to now have Python 3 put in in your Ubuntu system.

Whether or not you employ APT, compile from supply, or leverage a PPA, you possibly can simply set up Python on Ubuntu.

After putting in, don’t overlook to confirm the set up to make sure every thing went easily.

When you haven’t put in PIP but, take into account doing so, as it’s important for managing Python packages.



Supply hyperlink

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles