Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»Python»How To Install Python 3.9 on Ubuntu 18.04

    How To Install Python 3.9 on Ubuntu 18.04

    RahulBy RahulOctober 20, 20203 Mins ReadUpdated:July 17, 2021

    Python is an object-oriented, high-level programming language. It is open-source with a large community. Python is used as a key language among the top tech companies like Google.

    The latest stable version Python 3.9 is out with several improvements and security updates. It included multiple new modules, improved existing modules and many other features.

    This tutorial will help you to install Python 3.9 on Ubuntu 18.04 LTS system. You will find two methods to install Python. First method will use deadsnakes PPA to install Python. The second method will use Python’s source code for the installation.

    Follow the below tutorial and choose one method to install Python 3.9. Both the methods are tested with the latest Ubuntu 18.04 system.

    Prerequisites

    Before beginning the Python installation, install some required packages on your system. Login to your Ubuntu system and execute following commands:

    sudo apt update 
    sudo apt install software-properties-common 
    

    Install Python 3.9 Using Apt-Get

    The Apt package manager provides simple way for installing Python 3.9 on Ubuntu system. Follow the steps below:

    • Open a terminal on your system and configure deadsnakes PPA to your system.
      sudo add-apt-repository ppa:deadsnakes/ppa 
      
    • Once you added the PPA on your Ubuntu system, update the apt cache and install Python 3.9 on Ubuntu.
      sudo apt update 
      sudo apt install python3.9 
      
    • Wait for the installation to complete. Check the Python version by executing:
      python3.9 -V 
      
      Python 3.9.6
      

    That’s it. Python 3.9 is installed on your Ubuntu system and ready to use.

    Install Python 3.9 Using Source Code

    As the Debian packages are available, We don’t recommend installing Python 3.9 packages from source code. But in some cases, you may need to install Python from the source code.

    So follow the below instructions to install Python 3.9 using source code on Ubuntu 18.04 Linux system.

    • First of all, install essential packages for compiling source code. Open a terminal and execute following commands:
      sudo apt install wget build-essential checkinstall 
      sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
          libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev 
      
    • Now, download the Python 3.9 source code from the official download site. Switch to a relevant directory and use wget to download the source file.
      cd /opt 
      sudo wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz 
      
    • Next, extract the downloaded archive file and prepare the source for the installation.
      tar xzf Python-3.9.6.tgz 
      cd Python-3.9.6 
      sudo ./configure --enable-optimizations 
      
    • Python source is ready to install. Execute make altinstall command to install Python 3.9 on your system.
      sudo make altinstall 
      

      make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

    • The Python 3.9 has been installed on Ubuntu 18.04 system. Verify the installed version:
      python3.9 -V 
      
      Python 3.9.6
      
    • Remove the downloaded archive to free space
      sudo rm -f /opt/Python-3.9.6.tgz 
      

    Conclusion

    In this tutorial, you have learned to install Python 3.9 on Ubuntu 18.04 using Apt and source code.

    Python Python3 Python3.9 Ubuntu 18.04
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Install NVM on CentOS/RHEL 8
    Next Article How To Install Elasticsearch on Fedora 34/33

    Related Posts

    How to accept user input in Python

    2 Mins Read

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    Setup Selenium with Python and Chrome on Ubuntu & Debian

    Updated:June 20, 20224 Mins Read

    Setup Selenium with Python and Chrome on Fedora

    Updated:June 18, 20223 Mins Read

    How to Install Apache Kafka on Ubuntu 22.04

    Updated:June 5, 20225 Mins Read

    Creating Python Virtual Environment on Windows

    Updated:June 3, 20222 Mins Read

    14 Comments

    1. John doe on June 3, 2022 2:28 pm

      nice tutorial as usual Many thanks.

      Reply
    2. Gerard on February 16, 2022 4:52 pm

      Works on armbian Orange pi One H3 512Mb, need more swap
      Debian GNU/Linux 10 (buster)

      Reply
    3. Rod on August 29, 2021 3:57 pm

      Now that it’s installed and by running command python3.0 -V it displays Python 3.9.6 – Awesome!
      Although it now has two different python version, How to make python 3.9.6 default as still showing python 3.8.10 if I run python3 -V ??

      Reply
    4. andres leonRangel on August 6, 2021 12:54 am

      everything worked great for me. Thanks a lot

      my output in ubuntu 2018
      /usr/bin/install -c -m 644 ./Misc/python.man \
      /usr/local/share/man/man1/python3.9.1
      if test “xupgrade” != “xno” ; then \
      case upgrade in \
      upgrade) ensurepip=”–altinstall –upgrade” ;; \
      install|*) ensurepip=”–altinstall” ;; \
      esac; \
      ./python -E -m ensurepip \
      $ensurepip –root=/ ; \
      fi
      Looking in links: /tmp/tmpxie6sw67
      Processing /tmp/tmpxie6sw67/setuptools-56.0.0-py3-none-any.whl
      Processing /tmp/tmpxie6sw67/pip-21.1.3-py3-none-any.whl
      Installing collected packages: setuptools, pip
      Successfully installed pip-21.1.3 setuptools-56.0.0
      WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

      That was successful

      Reply
    5. Mansi on June 7, 2021 7:05 am

      Hi, there is some problem in extracting the downloaded archive files.
      I am getting this message for all the files in the source zipped package

      tar: Python-3.9.4: Cannot mkdir: Permission denied
      tar: Python-3.9.4/CODE_OF_CONDUCT.md: Cannot open: No such file or directory

      Can you suggest why is it and what can i do? thanks

      Reply
      • rsh on June 14, 2021 11:50 pm

        with sodu tar xzf Python-3.9.4.tgz . do it

        Reply
    6. Tamás on May 21, 2021 2:13 pm

      I can’t open the terminals

      Reply
    7. Recursion on May 7, 2021 9:28 am

      how do you install pip for python3.9?

      Reply
      • Kuna on August 6, 2021 2:29 am

        It has it already

        Reply
    8. Kevin A on April 14, 2021 6:51 pm

      One missing tidbit: How to install pip3

      Reply
    9. John on March 13, 2021 5:26 am

      Hello,

      What are the consequences of installing Python 3.9 in Ubuntu 18.04 using this method?

      Reply
      • Div on April 7, 2021 4:29 pm

        terminal not opening

        Reply
        • Sourav Pathak on October 12, 2021 7:12 pm

          terminal gone

          Reply
    10. Tariq Mehmood on January 27, 2021 8:53 pm

      Good work verified

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How To Install Docker on Ubuntu 22.04
    • How to Install Bower on Ubuntu 22.04 & 20.04
    • How to run “npm start” through Docker
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.