Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»Python»How To Install Python 3.11 on CentOS 9/8 & Fedora

    How To Install Python 3.11 on CentOS 9/8 & Fedora

    By RahulJanuary 26, 20232 Mins Read

    Python 3.11 is recently launched with multiple improvements and security upgrades. This version provides developers to easily debug their code with fine-grained error locations in tracebacks. The new “Self” annotation provides a simple way to annotate methods that return an instance of their class.

    Advertisement

    Mostly the latest operating systems come with the latest Python versions. But the OS versions released before the release of Python 3.11 may not have the latest version. This tutorial will help you to install Python 3.11 on your CentOS, Red Hat & Fedora operating systems by compiling it from source code.

    Requirements

    This Python installation required a GCC compiler on your system. Login to your server using ssh or shell access. Now, use the following command to install prerequisites for Python before installing it.

    sudo dnf install gcc openssl-devel bzip2-devel sqlite-devel 
    
    • Read: How to Use SSH to Connect Remote Linux Server

    Step 1: Download Python 3.11

    Download Python using the following command from the Python official site. You can also download the latest version in place of specified below.

    cd /usr/src 
    wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz 
    

    Now extract the downloaded package.

    tar xzf Python-3.11.1.tgz 
    

    Step 2: Install Python 3.11 on CentOS & Fedora

    Use the below set of commands to compile Python source code using the ./configure script and the make with altinstall.

    cd Python-3.11.1 
    sudo ./configure --enable-optimizations 
    sudo make altinstall 
    

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

    Now remove the downloaded source archive file from your system

    sudo rm /usr/src/Python-3.11.1.tgz 
    

    Step 3: Check Python Version

    Check the latest version installed of python using the below command.

    python3.11 -V 
    
    Python 3.11.1
    

    Conclusion

    In this tutorial, you have found the instructions to install Python 3.11 on CentOS, RHEL, and Fedora systems by compiling it from the source code. We still suggest to the package manager for the Python installation, but if the package manager is failing to do it, compile it from the source code.

    Install python Python Python3 Python3.11
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Python 3.11 on Amazon Linux 2

    Installing Python 3.11 on Debian Linux

    How To Install Python 3.11 on Debian 11/10

    Installing Python 3.11 on Ubuntu, Debian and LinuxMint

    How To Install Python 3.11 on Ubuntu, Debian and LinuxMint

    View 27 Comments

    27 Comments

    1. Danny on July 6, 2021 11:39 pm

      What if I don’t want it installed in /usr/local/bin but in /usr/bin instead?
      What should I change?

      Reply
    2. maxmoon on January 17, 2020 3:42 pm

      How to remove old Python installations like this?
      Since Python 3.3 I try to get the newest version of Python3 in CentOS6 with this method.
      Now I have a system which has Python 3.3, 3.4 … 3.9 and between installed, but I don’t need all of them.
      Is there a save way to uninstall those again?

      P.S.: reCAPTCHA is a huge NO-GO!

      Reply
      • ffauchille on February 7, 2020 3:30 pm

        I guess you could just remove the /usr/bin/python binary by a symlink to python3.6:

        rm /usr/bin/python
        ln -s /usr/local/bin/python3.6 /usr/local/bin

        Reply
        • ffauchille on February 7, 2020 3:32 pm

          Sorry for the typo, here is the good one:

          rm /usr/bin/python
          ln -s /usr/local/bin/python3.6 /usr/bin/python

          Reply
    3. Kausik on October 15, 2019 6:08 am

      This worked like charm.
      For RHEL 7.4, python 3.6, I later started getting ‘ModuleNotFoundError’ for ‘import nltk’.
      The reason is that sqlite3 wasn’t compiled properly.
      I installed sqlite-devel and recompiled python 3.6 – which had the issue fixed.
      yum install sqlite-devel
      /usr/src/Python-3.6.9 #Had the src already downloaded and extracted here
      ./configure –enable-optimizations
      make altinstall

      Reply
    4. Darwin on September 20, 2019 11:59 pm

      Thank you for the notes.
      Installed on a barebones RHEL7.7, during the make altinstall step I got the error
      ModuleNotFoundError: No module named ‘_ctypes’
      make: *** [altinstall] Error 1
      Installed the package libffi-devel and it worked perfectly.
      Known bug – https://bugs.python.org/issue31652

      Reply
    5. SRIRAM.V on April 30, 2019 10:41 am

      Thank you Rahul , this worked great for RHEL , no one seemed to have this Documented well anywhere else.

      Reply
    6. waketzheng on March 27, 2019 10:55 am

      It worked for centos6. Thanks~

      Reply
    7. Brian on March 16, 2019 7:01 pm

      thank you sir

      Reply
    8. Rob T. on August 16, 2018 12:59 pm

      For most people, building Python from source isn’t good advice. Look through the comments that are already here.

      1 – There is no uninstal command, you are manually making changes to your system as root.
      2 – The dependency list to get all of the standard library modules (SSL, compression, database, etc. ) is long. See the above comments. Check one of the source RPMs for a full list of the packages that should be pre-installed. The details aren’t easy to get right. That’s why we have rpm and yum.
      3 – If you accidentally run ‘make install’ as root, you will likely break yum and other system admin utilities. This is tricky to recover from.
      4 – If there are bugs/security vulnerabilities in any of the underlying libraries, how will you know when you need to patch and rebuild your personal python build?
      5 – For companies that are using RHEL, there is usually an expectation of support from Red Hat. You can get a supported Python 3 from Red Hat via Software Collections. If you install from source, you are completely on your own.

      Reply
    9. Deepak on July 4, 2018 5:32 am

      I want to install some python 3.6 packages with yum command without using pip so where can I get the required repository for it ?

      Reply
    10. Kvark on May 16, 2018 1:08 pm

      having same issue, not found, fied by:
      # PATH=”/usr/local/bin:$PATH”

      also will be good to add aliases, add these to your .bashrc:
      alias python3=’/usr/local/bin/python3.5′
      alias pip3=’/usr/local/bin/pip3.5′
      # (without this sudo does not see aliases)
      alias sudo=’sudo ‘

      Reply
    11. JK on May 13, 2018 3:12 am

      Thank you!

      Later, when I wonder other things, Can I ask you??
      I’m a junior developer..

      Reply
    12. Riad on April 2, 2018 7:14 pm

      Thanks a lot ….

      Reply
    13. Sridhar on March 28, 2018 5:13 pm

      Thanks Rahul.

      These instructions were helpful to me in installing Python 3.6 as a separate installation on top of current python 2.6 on Redhat 6

      Reply
    14. Andrew on November 23, 2017 6:53 am

      PIP fails when i run pip to install a package I get “ImportError: cannot import name ‘main'”

      Reply
      • Rahul K. on November 23, 2017 7:08 am

        Hi Andrew, I have successfully installed modules with pip3.6.

        $ pip3.6 install pypiHello

        Collecting pypiHello
        Downloading pypiHello-1.2.zip
        Installing collected packages: pypiHello
        Running setup.py install for pypiHello … done
        Successfully installed pypiHello-1.2

        Reply
    15. Eli Boyarski on November 22, 2017 12:10 pm

      This method builds a python executable without ssl support and without bz2 support.
      Install openssl-devel and bzip2-devel before running configure.

      Also, run “configure –enable-optimizations” to get standard optimizations.

      Lastly, you may want to add some useful symlinks after installation, mapping e.g. pip3.6 to pip3, python3.6 to python3, etc..

      Reply
      • Rahul K. on November 23, 2017 4:28 am

        Thanks Eli, I have updated our tutorial as per your suggestions

        Reply
    16. krishna on October 24, 2017 8:27 am

      #cd Python-3.6.1
      No such file or directory

      Reply
    17. GW on July 27, 2017 5:41 pm

      Could you please specify which, if any operation is to be done as root?
      Thanks!

      Reply
    18. Tom on May 22, 2017 5:58 pm

      I get “zipimport.ZipImportError: can’t decompress data; zlib not available” when doing “make altinstall”. I know zlib is installed because “yum install zlib” gives me “Package zlib-1.2.7-17.el7.x86_64 already installed and latest version”

      Reply
      • Nash on October 6, 2017 4:11 pm

        yum install zlib-devel will solve the zlip error.

        Reply
    19. alp on May 3, 2017 12:41 am

      And how can I remove Python 3.6 after these instructions?
      I use Spyder and this software didn’t recognize Py 3.6 (only its version 3.5).
      Thanks in advance

      Reply
    20. Dk on April 25, 2017 12:17 am

      I follow step by step and always get the error: python3.6: command not found

      Reply
      • Baard Helmen on May 9, 2017 1:15 pm

        Try to use: python3

        Reply
        • Tyler on July 26, 2017 6:11 pm

          Also, ensure that /usr/local/bin is in your PATH.

          Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    • sleep Command in Linux with Examples
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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