How to Install Python in Ubuntu Linux (4 Methods) (4 Methods)

Typically, Python comes pre-installed in Ubuntu, but when it’s not accessible in your Linux distro for some purpose, you’ll be able to set up Python in Ubuntu in a number of steps. When you’re a developer, Python is important to construct numerous software program and web sites. Apart from that, plenty of Ubuntu’s software program … The post How to Install Python in Ubuntu Linux (4 Methods) (4 Methods) appeared first on Ferdja.

May 5, 2023 - 02:00
 3
How to Install Python in Ubuntu Linux (4 Methods) (4 Methods)

Typically, Python comes pre-installed in Ubuntu, but when it’s not accessible in your Linux distro for some purpose, you’ll be able to set up Python in Ubuntu in a number of steps. When you’re a developer, Python is important to construct numerous software program and web sites. Apart from that, plenty of Ubuntu’s software program depends on Python, so you could have it for the sleek functioning of the OS. On that observe, let’s go forward and learn to set up Python in Ubuntu.

Set up Python in Ubuntu (2022)

On this tutorial, we now have included 3 ways to get Python on Ubuntu. However earlier than that, let’s examine if Python is already put in in your system and replace it accordingly.

Notice: We examined the instructions and strategies listed beneath on the newest model, i.e. Ubuntu 22.04 LTS and Ubuntu 20.04.

Test If Python is Already Put in on Ubuntu

Prior to installing Python in Ubuntu, it’s best to examine whether or not it’s already put in in your system. This lets you replace the present Python set up with out having to put in it from scratch once more. It must also come in useful in case you ever want to downgrade to a special Python model. With that stated, listed below are the steps to comply with.

1. First, open Terminal utilizing the “Alt + Ctrl + T” keyboard shortcut and run the beneath command. If the command provides an output with the model quantity, it means you have already got Python put in in Ubuntu. To exit Python’s setting, press “Ctrl + D”. In case you get an error message like “Command not discovered”, you don’t have Python put in. So transfer to the subsequent methodology to put in it.

python3
Check If Python is Already Installed in Ubuntu

2. You too can run the beneath command to examine the Python model in your Ubuntu set up.

python3 --version
Check If Python is Already Installed in Ubuntu

3. If an older model of Python is put in, run the beneath command to replace Python to the newest model in your Linux distro.

sudo apt --only-upgrade set up python3
Check If Python is Already Installed in Ubuntu

Set up Python in Ubuntu from Official Repository

Python is obtainable in Ubuntu’s official repository, so that you don’t should do a lot aside from execute a easy command to seamlessly set up it in your system. Right here is methods to do it.

1. Open Terminal in Ubuntu and run the beneath command to replace all of the packages and repositories.

sudo apt replace && sudo apt improve -y
Install Python in Ubuntu From Official Repository

2. Subsequent, set up Python in Ubuntu by working the beneath command. It will robotically set up Python in your machine.

sudo apt set up python3
Install Python in Ubuntu From Official Repository

Set up Python in Ubuntu from Deadsnakes PPA

Aside from the official repository, you can even pull newer variations of Python from Deadsnakes PPA, which is standard for internet hosting new and previous variations of Python. If Ubuntu’s official repository (APT) was unable to put in Python in your system, this could actually work. Listed here are the steps to comply with.

1. Fireplace up the Terminal utilizing the “Alt + Ctrl + T” shortcut and run the beneath command. That is wanted to handle your distribution and software program sources from impartial distributors.

sudo apt set up software-properties-common
Deadsnakes PPA (Newer Versions)

2. Subsequent, run the beneath command to add Deadsnakes PPA to Ubuntu’s repository. When prompted, press Enter to proceed.

sudo add-apt-repository ppa:deadsnakes/ppa
Deadsnakes PPA (Newer Versions)

3. Now, replace the package deal checklist and run the subsequent command to set up Python.

sudo apt replace
sudo apt set up python3
Deadsnakes PPA (Newer Versions)

4. You too can select to set up a selected model (previous or new) of Python from Deadsnakes PPA. It additionally hosts nightly builds of Python (experimental), so you’ll be able to set up them as nicely. Run the instructions within the following trend:

sudo apt set up python3.12

or

sudo apt set up python3.11
Deadsnakes PPA (Newer Versions)

Construct Python in Ubuntu from the Supply Code

When you want to go the additional mile and construct Python immediately in Ubuntu from the supply code, you are able to do so. However keep in mind, it’s a barely lengthier course of and would possibly require greater than quarter-hour to compile Python, relying in your {hardware} specs. Listed here are the steps you want to comply with.

1. First, open the Terminal and run the beneath command to replace the packages.

sudo apt replace
Build Python in Ubuntu From Source Code

2. After that, run the subsequent command to put in the required dependencies to construct Python in Ubuntu.

sudo apt set up build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Build Python in Ubuntu From Source Code

3. Subsequent, create a “python” folder and transfer to the stated folder. When you get a “Permission denied” error, run the command with sudo.

sudo mkdir /python && cd /python
Build Python in Ubuntu From Source Code

4. Following that, use wget to obtain the newest model of Python from the official website. Right here, I’m downloading Python 3.12.0a1.

sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0a1.tgz
Build Python in Ubuntu From Source Code

5. Now, extract the downloaded file utilizing the tar command and transfer to the extracted folder.

sudo tar -xvf Python-3.12.0a1.tgz
cd Python-3.12.0a1
  • Build Python in Ubuntu From Source Code
  • Build Python in Ubuntu From Source Code

6. After that, run the beneath command to activate optimizations earlier than constructing Python in Ubuntu. It will cut back the time for Python compilation.

./configure --enable-optimizations
Build Python in Ubuntu From Source Code

7. Lastly, execute the beneath command to construct Python in Ubuntu. It will take anyplace between 10 to fifteen minutes to finish the method.

sudo make set up
Build Python in Ubuntu From Source Code

8. As soon as it’s achieved, run the python3 --version command to examine the Python model quantity. And you might be achieved.

Build Python in Ubuntu From Source Code

Set up or Replace Python in Ubuntu in 4 Simple Methods

So that is how one can set up Python in Ubuntu Linux. When you didn’t select a minimal setup throughout set up, you then possible have Python put in in your system. Then, you solely have to examine the model and replace the present Python set up. Nevertheless, in case you don’t have Python put in, you’ll be able to comply with one of many three strategies described above to put in it instantly. Anyway, that’s all from us. If you wish to run Android apps in Linux with out an emulator, comply with our information for detailed directions. Lastly, when you’ve got any questions, tell us within the remark part beneath.

The post How to Install Python in Ubuntu Linux (4 Methods) (4 Methods) appeared first on Ferdja.