How to install Python on Ubuntu 18.04

How to install Python on Ubuntu 18.04

Install Python on Ubuntu 18.04

In Ubuntu 18.04, python 3 is installed as a default interpreter. In a minimal Ubuntu installation, this is not pre-installed, so install Python on Ubuntu 18.04.

Prerequisites

Before installing Python on Ubuntu 18.04. The server requires a non-root user account with sudo privileges.

Before you start

Before you start, make sure you have Python installed on your system.

python --version

If the output shows the Python version, either you already have Python installed, or if you can’t find the command, Python is not installed. However, you can also upgrade or downgrade your Python version.

Install Python 3 on Ubuntu

Update the package manager index by entering the following command:

sudo apt update

The following command provides a minimal installation of Python. To install Python 3, enter the following command

sudo apt install python3-minimal

Check the installation and check the Python version by entering the following command:

python3 -V

The output looks like this:

Output
    Python 3.6.6

Install Python 2 on Ubuntu

Before installing Python on ubuntu 18.04, enter the following command to update the package manager index:

sudo apt update

The following command provides a minimal installation of Python. To install Python 2, enter the following command:

sudo apt install pytho3-minimal

Check the installation and check the Python version by entering the following command:

python --version

The output is as follows:

Output:
    Python 2.7.15rc1

Install Python module

There are already many Python modules in the Ubutnu repository. Enter the following command to find the Python module

sudo apt search MODULE_NAME

To install the found python module, enter the following command

sudo apt install MODULE_NAME

The best way to install and manage Python packages

PIP stands for Python Package Index, the most common tool for installing and managing Python packages. You can find more information about this tool at the following link: How to Install PIP on Ubuntu 18.04

Conclusion

Here, you learned how to install Python on Ubuntu 18.04. If you have any questions about this, please comment below.

Sidebar