# Python install

**Introduction**

**Python** is a popular programming language often used to write scripts for operating systems. It’s versatile enough for use in web development and app design.

**In this tutorial you will learn how to install Python 3.8 on Ubuntu 18.04 or Ubuntu 20.04.**

![](https://phoenixnap.com/kb/wp-content/uploads/2021/04/install-python-3-on-ubuntu.png)

Prerequisites

* A system running Ubuntu 18.04 or Ubuntu 20.04
* A user account with **sudo** privileges
* Access to a terminal window/command-line (**Ctrl**–**Alt**–**T**)
* Make sure your environment is configured to use Python 3.8

### Option 1: Install Python 3 Using apt (Easier) <a href="#ftoc-heading-1" id="ftoc-heading-1"></a>

This process uses the **apt package manager** to install Python. There are fewer steps, but it’s dependent on a third party hosting software updates. You may not see new releases as quickly on a third-party repository.

Most factory versions of Ubuntu 18.04 or Ubuntu 20.04 come with Python pre-installed. [Check your version of Python](https://phoenixnap.com/kb/check-python-version) by entering the following:

```
python --version
```

If the revision level is lower than 3.7.x, or if Python is not installed, continue to the next step.

#### Step 1: Update and Refresh Repository Lists <a href="#ftoc-heading-2" id="ftoc-heading-2"></a>

Open a terminal window, and enter the following:

```
sudo apt update
```

#### Step 2: Install Supporting Software <a href="#ftoc-heading-3" id="ftoc-heading-3"></a>

The software-properties-common package gives you better control over your package manager by letting you add PPA (Personal Package Archive) repositories. Install the supporting software with the command:

```
sudo apt install software-properties-common
```

![](https://phoenixnap.com/kb/wp-content/uploads/2021/04/install-supporting-software-for-python.png)

#### Step 3: Add Deadsnakes PPA <a href="#ftoc-heading-4" id="ftoc-heading-4"></a>

Deadsnakes is a PPA with newer releases than the default Ubuntu repositories. Add the PPA by entering the following:

```
sudo add-apt-repository ppa:deadsnakes/ppa
```

The system will prompt you to press enter to continue. Do so, and allow it to finish. Refresh the package lists again:

```
sudo apt update
```

#### Step 4: Install Python 3 <a href="#ftoc-heading-5" id="ftoc-heading-5"></a>

Now you can start the installation of Python 3.8 with the command:

```
sudo apt install python3.8
```

Allow the process to complete and verify the Python version was installed sucessfully::

```
python --version
```

![](https://phoenixnap.com/kb/wp-content/uploads/2021/04/check-python-version.png)

### Option 2: Install Python 3.7 From Source Code (Latest Version) <a href="#ftoc-heading-6" id="ftoc-heading-6"></a>

Use this process to download and compile the source code from the developer. It’s a bit more complicated, but the trade-off is accessing a newer release of Python.

#### Step 1: Update Local Repositories <a href="#ftoc-heading-7" id="ftoc-heading-7"></a>

To update local repositories, use the command:

```
sudo apt update
```

#### Step 2: Install Supporting Software <a href="#ftoc-heading-8" id="ftoc-heading-8"></a>

Compiling a package from source code requires additional software.

Enter the following to install the required packages for Python:

```
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
```

![](https://phoenixnap.com/kb/wp-content/uploads/2021/04/install-supporting-software-for-python.png)

#### Step 3: Download the Latest Version of Python Source Code <a href="#ftoc-heading-9" id="ftoc-heading-9"></a>

To download the newest release of Python Source Code, navigate to the **`/tmp`** directory and use the **`wget`** command:

```
cd /tmp
```

```
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
```

![](https://phoenixnap.com/kb/wp-content/uploads/2021/04/download-python-from-source-on-ubuntu.png)

**Note:** The source code is different from the software found on the main download page. At the time this article was written, Python 3.7.5 was the latest version available.

#### Step 4: Extract Compressed Files <a href="#ftoc-heading-10" id="ftoc-heading-10"></a>

Next, you need [to extract the tgz file](https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line) you downloaded, with the command:

```
tar -xf Python-3.8.3.tgz
```

#### Step 5: Test System and Optimize Python <a href="#ftoc-heading-11" id="ftoc-heading-11"></a>

Before you install the software, make sure you test the system and optimize Python.

The **`./configure`** command evaluates and prepares Python to install on your system. Using the **`--optimization`** option speeds code execution by 10-20%.

Enter the following:

```
cd python-3.8.3
```

```
./configure --enable-optimizations
```

This step can take up to 30 minutes to complete.

#### Step 6: Install a Second Instance of Python (recommended) <a href="#ftoc-heading-12" id="ftoc-heading-12"></a>

To create a second installation of Python 3.835, in addition to your current Python installation, enter the following:

```
sudo make altinstall
```

It is recommended that you use the **`altinstall`** method. Your Ubuntu system may have software packages dependent on Python 2.x.

**(Option) Overwrite Default Python Installation**&#x20;

To install Python 3.8.3 over the top of your existing Python, enter the following:

```
sudo make install
```

Allow the process to complete.

#### Step 7: Verify Python Version <a href="#ftoc-heading-14" id="ftoc-heading-14"></a>

Enter the following:

```
python3 --version
```

**Note:** If you are starting with Python and are still looking for the right IDE or editor, see our comprehensive overview of the [best Python IDEs and code editors](https://phoenixnap.com/kb/best-python-ide-code-editor).

### Using Different Versions of Python <a href="#ftoc-heading-15" id="ftoc-heading-15"></a>

If you used the **`altinstall`** method, you have two different versions of Python on your system at the same time. Each installation uses a different command.

Use the **`python`** command to run commands for any older Python 2.x version on your system. For example:

```
python --version
```

To run a command using the newer version, use **`python3`**. For example:

```
python3 --version
```

It is possible to have multiple major (3.x or 2.x) versions of Python on your system. If you have Python 3.7.x and Python 3.8.x both installed, use the second digit to specify which version you want to use:

```
python3.7 --version
```

```
python3.8 --version
```

Conclusion

You should now have a working installation of Python 3 on your Ubuntu system. Next, consider [installing PIP for Python](https://phoenixnap.com/kb/how-to-install-pip-on-ubuntu) if you haven’t already.

With everything set, you can start with some basics scripts like [getting the current time and date in Python](https://phoenixnap.com/kb/get-current-date-time-python) or learn [file handling in Python](https://phoenixnap.com/kb/file-handling-in-python) with built-in methods, which include creating, opening, and closing files.
