Article directory
Install Python on Ubuntu, no more worries! There is always one of the 4 methods that suits you! ✌✌✌
Detailed tutorials will teach you step by step, and even a novice can become a master in seconds!
Say goodbye to tedious steps and easily own Python artifact! Join me to unlock the new world of Python!
Generally speaking, Ubuntu system comes with Python pre-installed, but if unfortunately your Linux Don't worry if Python is not provided with your distribution, installing Python in Ubuntu only takes a few simple steps.
Python is an essential tool for developers to build a variety ofsoftwareand website.
Furthermore, many Ubuntu software depend on Python, so in order to run the operating system smoothly, you must install it.
So, let’s see how to install Python in Ubuntu.
Install Python on Ubuntu
In this guide, we'll cover three ways to get Python on Ubuntu. But before that, let’s check whether your system has Python installed and update it accordingly.
note:We tested the commands and methods listed below on the latest versions, namely Ubuntu 22.04 LTS and Ubuntu 20.04.
Check if Ubuntu has Python installed
Before installing Python on Ubuntu, you should check whether Python is already installed on your system. This way you can update an existing Python installation without having to install it from scratch. This also comes in handy if you want to downgrade to a different Python version. Here are the specific steps.
1. First, use the keyboard shortcut "Alt + Ctrl + T" to open the terminal and run the following command. If the command outputs a version number, it means that Python is already installed in Ubuntu. To exit the Python environment, press "Ctrl + D". If you receive an error message like "Command not found", you don't have Python installed yet. So, move on to the next installation method.
python3
2. You can also run the following command to check the Python version on Ubuntu.
python3 --version
3. If you have an older version of Python installed, run the following command to upgrade Python to the latest version on your Linux distribution.
sudo apt --only-upgrade install python3
Install Python in Ubuntu from the official software repository
Python is available in the Ubuntu official software repository, so you only need to execute a simple command to seamlessly install Python on your system. Here's how to install it.
1. Open a terminal in Ubuntu and run the following command to update all software packages and software sources.
sudo apt update && sudo apt upgrade -y
2. Next, run the following command to install Python in Ubuntu. This will automatically install Python on your machine.
sudo apt install python3
Install Python in Ubuntu from Deadsnakes PPA
In addition to the official repository, you can also pull newer versions of Python from the Deadsnakes PPA. If the official Ubuntu repository (APT) cannot install Python on your system, this method will definitely work. Below are the installation steps.
1. Use the "Alt + Ctrl + T" shortcut key to start the terminal and run the following command. This is needed to manage your distribution and software sources from independent vendors.
sudo apt install software-properties-common
2. Next, run the following command to add the Deadsnakes PPA to Ubuntu's software repositories. When prompted, press Enter to continue.
sudo add-apt-repository ppa:deadsnakes/ppa
3. Now, update the package list and run the next command to install Python.
sudo apt update sudo apt install python3
4. You can also choose to install a specific version (old or new) of Python from the Deadsnakes PPA. It also provides nightly builds (experimental) of Python, so you can install those too. Run the command as follows:
sudo apt install python3.12
Or
sudo apt install python3.11
Building Python in Ubuntu from source
If you want to go a step further and compile Python directly from source in Ubuntu, you can do that too. But keep in mind that this process will be a little longer, compiling Python may take more than 15 minutes, depending on your hardware specifications. Here are the steps you need to follow.
1. First, open a terminal and run the following command to update the software package.
sudo apt update
2. Then, run the next command to install the required dependencies to build Python in Ubuntu.
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
3. Then, create a “python” folder and move to it. If you get a "Permission denied" error, use sudo
Run this command.
sudo mkdir /python && cd /python
4. Then, use wget
Download the latest version of Python from the official website. Here, I downloaded Python 3.12.0a1.
sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0a1.tgz
5. Now, use tar
command to decompress the downloaded file and move it to the decompressed folder.
sudo tar -xvf Python-3.12.0a1.tgz cd Python-3.12.0a1
6. Then, run the following command to turn on optimization before compiling Python in Ubuntu. This will shorten Python compilation time.
./configure --enable-optimizations
7. Finally, execute the following command to build Python in Ubuntu. The entire process takes 10 to 15 minutes.
sudo make install
8. Once completed, run python3 --
version
command to check if Python is installed successfully.
The above are four ways to install Python in Ubuntu. Choose the method that suits your needs, and after installing Python, you can happily write Python code in Ubuntu.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "Installing Python on Ubuntu, there are 4 methods, one of which is suitable for you!" Even novices can do it easily! 》, helpful to you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-31420.html
Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!