{"id":152894,"date":"2025-09-06T19:06:39","date_gmt":"2025-09-06T16:06:39","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=152894"},"modified":"2025-09-06T19:06:42","modified_gmt":"2025-09-06T16:06:42","slug":"how-to-python-3-12-on-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/how-to-python-3-12-on-ubuntu-linux\/","title":{"rendered":"How To Install Python 3.12 on Ubuntu 22.04|20.04|18.04"},"content":{"rendered":"\n<p>Welcome to today&#8217;s article on how to install and configure <a href=\"https:\/\/computingforgeeks.com\/how-to-install-python-on-kali-linux-linux-mint\/\">Python 3.12<\/a> on Ubuntu 22.04 \/ Ubuntu 20.04 \/ Ubuntu 18.04 Linux system. Our installation is performed from source to ensure we build the latest release of Python 3.12 programming language. Python is an easy to learn and master, interpreted programming language known to simple and highly readable. The first release of Python was in 1991 and it currently has a large and active community of contributors and developers.<\/p>\n\n\n<p>[ebook product=&#8221;2&#8243; theme=&#8221;dark&#8221;]<\/p>\n\n\n\n<p>At the time of updating this article, Python 3.12.x is the newest major release of the Python programming language. This release contains many new features and optimizations. Some of the new features includes the following.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.python.org\/3.12\/whatsnew\/3.12.html#pep-688-making-the-buffer-protocol-accessible-in-python\" target=\"_blank\" rel=\"noreferrer noopener\">Support for the buffer protocol<\/a>&nbsp;in Python code (<a href=\"https:\/\/peps.python.org\/pep-0688\/\" target=\"_blank\" rel=\"noreferrer noopener\">PEP 688<\/a>).<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3.12\/whatsnew\/3.12.html#pep-701-syntactic-formalization-of-f-strings\" target=\"_blank\" rel=\"noreferrer noopener\">More flexible f-string parsing<\/a>, allowing many things previously disallowed (<a href=\"https:\/\/peps.python.org\/pep-0701\/\" target=\"_blank\" rel=\"noreferrer noopener\">PEP 701<\/a>).<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3.12\/whatsnew\/3.12.html#pep-669-low-impact-monitoring-for-cpython\" target=\"_blank\" rel=\"noreferrer noopener\">A new debugging\/profiling API<\/a>&nbsp;(<a href=\"https:\/\/peps.python.org\/pep-0669\/\" target=\"_blank\" rel=\"noreferrer noopener\">PEP 669<\/a>).<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3.12\/whatsnew\/3.12.html#improved-error-messages\" target=\"_blank\" rel=\"noreferrer noopener\">Even more improved error messages<\/a>. More exceptions potentially caused by typos now make suggestions to the user.<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3.12\/whatsnew\/3.12.html#pep-684-a-per-interpreter-gil\" target=\"_blank\" rel=\"noreferrer noopener\">Support for isolated subinterpreters<\/a>&nbsp;with separate Global Interpreter Locks (<a href=\"https:\/\/peps.python.org\/pep-0684\" target=\"_blank\" rel=\"noreferrer noopener\">PEP 684<\/a>).<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3.12\/howto\/perf_profiling.html\" target=\"_blank\" rel=\"noreferrer noopener\">Support for the Linux&nbsp;<code>perf<\/code>&nbsp;profiler<\/a>&nbsp;to report Python function names in traces.<\/li>\n\n\n\n<li><a href=\"https:\/\/docs.python.org\/3.12\/whatsnew\/3.12.html#optimizations\" target=\"_blank\" rel=\"noreferrer noopener\">Many large and small performance improvements<\/a>&nbsp;(like&nbsp;<a href=\"https:\/\/peps.python.org\/pep-0709\/\" target=\"_blank\" rel=\"noreferrer noopener\">PEP 709<\/a>&nbsp;and support for the BOLT binary optimizer), delivering an estimated 5% overall performance improvement.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Install dependencies<\/h2>\n\n\n\n<p>Before we begin the installation, let&#8217;s update the OS package index.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p>Install all the dependencies required to build and run Python 3.12 on Ubuntu.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install wget libncurses5-dev build-essential zlib1g-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev pkg-config -y<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Download and install Python 3.12<\/h2>\n\n\n\n<p>After installing the package dependencies, download the latest available Python 3.12 gzipped tarball from the<a href=\"https:\/\/www.python.org\/downloads\/source\/\" target=\"_blank\" rel=\"noreferrer noopener\"> Python official release page<\/a>. We can do this using <code>wget<\/code> command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/www.python.org\/ftp\/python\/3.12.2\/Python-3.12.2.tgz<\/code><\/pre>\n\n\n\n<p>Extract the downloaded archive file after downloading it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xf Python-3.12.*.tgz<\/code><\/pre>\n\n\n\n<p>Change to created directory after file extraction.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd Python-3.12.*\/<\/code><\/pre>\n\n\n\n<p>Initiate configurations of Python before doing the installation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/configure --enable-optimizations<\/code><\/pre>\n\n\n\n<p>Sample output on the execution.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>checking build system type... x86_64-pc-linux-gnu\nchecking host system type... x86_64-pc-linux-gnu\nchecking for Python interpreter freezing... .\/_bootstrap_python\nchecking for python3.12... no\nchecking for python3.12... no\nchecking for python3.11... no\nchecking for python3.10... python3.10\nchecking Python for regen version... Python 3.10.12\nchecking for pkg-config... \/usr\/bin\/pkg-config\nchecking pkg-config is at least version 0.9.0... yes\nchecking for --enable-universalsdk... no\nchecking for --with-universal-archs... no\nchecking MACHDEP... \"linux\"\nchecking for gcc... gcc\nchecking whether the C compiler works... yes\nchecking for C compiler default output file name... a.out\nchecking for suffix of executables...\nchecking whether we are cross compiling... no\nchecking for suffix of object files... o\nchecking whether the compiler supports GNU C... yes\nchecking whether gcc accepts -g... yes\nchecking for gcc option to enable C11 features... none needed\nchecking how to run the C preprocessor... gcc -E\nchecking for grep that handles long lines and -e... \/usr\/bin\/grep\nchecking for a sed that does not truncate output... \/usr\/bin\/sed\nchecking for egrep... \/usr\/bin\/grep -E\nchecking for CC compiler name... gcc\nchecking for stdio.h... yes\nchecking for stdlib.h... yes\nchecking for string.h... yes\nchecking for inttypes.h... yes\nchecking for stdint.h... yes\nchecking for strings.h... yes\nchecking for sys\/stat.h... yes\nchecking for sys\/types.h... yes\n.....\nconfigure: creating .\/config.status\nconfig.status: creating Makefile.pre\nconfig.status: creating Misc\/python.pc\nconfig.status: creating Misc\/python-embed.pc\nconfig.status: creating Misc\/python-config.sh\nconfig.status: creating Modules\/Setup.bootstrap\nconfig.status: creating Modules\/Setup.stdlib\nconfig.status: creating Modules\/ld_so_aix\nconfig.status: creating pyconfig.h\nconfigure: creating Modules\/Setup.local\nconfigure: creating Makefile<\/code><\/pre>\n\n\n\n<p>Let&#8217;s now build Python 3.12 on Ubuntu Linux machine. The<strong><em> -j<\/em><\/strong> option is used to provide the number of cores available on the system for the build process:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make -j $(nproc)<\/code><\/pre>\n\n\n\n<p>Here is my command execution output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\nif test $? -ne 0 ; then \\\n\techo \"generate-posix-vars failed\" ; \\\n\trm -f .\/pybuilddir.txt ; \\\n\texit 1 ; \\\nfi\n.\/python -E -c 'import sys ; from sysconfig import get_platform ; print(\"%s-%d.%d\" % (get_platform(), *sys.version_info&#91;:2]))' &gt;platform\nThe necessary bits to build these optional modules were not found:\n_dbm                  _lzma                 _tkinter\n_uuid\nTo find the necessary bits, look in configure.ac and config.log.\n\nChecked 111 modules (31 built-in, 75 shared, 1 n\/a on linux-x86_64, 0 disabled, 4 missing, 0 failed on import)\nmake&#91;1]: Leaving directory '\/root\/Python-3.12.2'<\/code><\/pre>\n\n\n\n<p>After the build is done. Ansible installation can then be initiated by running the next commands.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo make altinstall<\/code><\/pre>\n\n\n\n<p>By using <code>altinstall<\/code>&nbsp;instead of&nbsp;<code>install<\/code>&nbsp;, the Python binary path will be&nbsp;<strong><em>\/usr\/bin\/python<\/em><\/strong>.<\/p>\n\n\n\n<p>Execution output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.......\nCreating directory \/usr\/local\/share\/man\/man1\n\/usr\/bin\/install -c -m 644 .\/Misc\/python.man \\\n\t\/usr\/local\/share\/man\/man1\/python3.12.1\nif test \"xupgrade\" != \"xno\"  ; then \\\n\tcase upgrade in \\\n\t\tupgrade) ensurepip=\"--altinstall --upgrade\" ;; \\\n\t\tinstall|*) ensurepip=\"--altinstall\" ;; \\\n\tesac; \\\n\t .\/python -E -m ensurepip \\\n\t\t$ensurepip --root=\/ ; \\\nfi\nLooking in links: \/tmp\/tmpdr48x63t\nProcessing \/tmp\/tmpdr48x63t\/pip-24.0-py3-none-any.whl\nInstalling collected packages: pip\nSuccessfully installed pip-24.0<\/code><\/pre>\n\n\n\n<p>Once complete, check the version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"> python3.12 --version<\/mark>\nPython 3.12.2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install Python Extensions \/ Modules<\/h2>\n\n\n\n<p>In Python, modules provide additional functionality not natively available in Python. Modules promotes code reusability, and general collaboration among developers.<\/p>\n\n\n\n<p><strong>Python Package manager<\/strong>&nbsp;(PIP) is used to install third-party modules. We can install specific Pip for Python version 3.12.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sS https:\/\/bootstrap.pypa.io\/get-pip.py | python3.12<\/code><\/pre>\n\n\n\n<p>Confirm the installation of Python Pip using the next commands.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">pip3.12 -V<\/mark>\npip 24.0 from \/usr\/local\/lib\/python3.12\/site-packages\/pip (python 3.12)<\/code><\/pre>\n\n\n\n<p>Installation of a module can then be done with the command syntax shown here.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">pip3.12<\/mark> install <em>module-name<\/em><\/code><\/pre>\n\n\n\n<p>Here is an example on installing <code>awscli<\/code> module.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"> sudo pip3.12 install <\/mark><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">awscli<\/mark><\/em>\n...\nDownloading awscli-1.32.49-py3-none-any.whl (4.4 MB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 4.4\/4.4 MB 31.3 MB\/s eta 0:00:00\nDownloading botocore-1.34.49-py3-none-any.whl (12.0 MB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 12.0\/12.0 MB 49.0 MB\/s eta 0:00:00\nDownloading PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724 kB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 725.0\/725.0 kB 19.5 MB\/s eta 0:00:00\nDownloading s3transfer-0.10.0-py3-none-any.whl (82 kB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 82.1\/82.1 kB 10.3 MB\/s eta 0:00:00\nDownloading jmespath-1.0.1-py3-none-any.whl (20 kB)\nDownloading pyasn1-0.5.1-py2.py3-none-any.whl (84 kB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 84.9\/84.9 kB 12.9 MB\/s eta 0:00:00\nDownloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 247.7\/247.7 kB 30.9 MB\/s eta 0:00:00\nDownloading urllib3-2.0.7-py3-none-any.whl (124 kB)\n   \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 124.2\/124.2 kB 22.0 MB\/s eta 0:00:00\nDownloading six-1.16.0-py2.py3-none-any.whl (11 kB)\nInstalling collected packages: urllib3, six, PyYAML, pyasn1, jmespath, docutils, colorama, rsa, python-dateutil, botocore, s3transfer, awscli\nSuccessfully installed PyYAML-6.0.1 awscli-1.32.49 botocore-1.34.49 colorama-0.4.4 docutils-0.16 jmespath-1.0.1 pyasn1-0.5.1 python-dateutil-2.8.2 rsa-4.7.2 s3transfer-0.10.0 six-1.16.0 urllib3-2.0.7<\/code><\/pre>\n\n\n\n<p>You can list all the installed modules using the command;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">pip3.12<\/mark> list<\/mark>\nPackage         Version\n--------------- -------\nawscli          1.32.49\nbotocore        1.34.49\ncolorama        0.4.4\ndocutils        0.16\njmespath        1.0.1\npip             24.0\npyasn1          0.5.1\npython-dateutil 2.8.2\nPyYAML          6.0.1\nrsa             4.7.2\ns3transfer      0.10.0\nsetuptools      69.1.1\nsix             1.16.0\nurllib3         2.0.7\nwheel           0.42.0\n...<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Python is the basis in building a strong foundation on the understanding of programming concepts and will surely open doors to diverse career opportunities if you are good at it. Installation of Python is the starting point to doing projects that solves varying needs and user needs.<\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Important links and resources<\/span><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.python.org\/3.12\/\" target=\"_blank\" rel=\"noreferrer noopener\">Official online Documentation<\/a>.<\/li>\n\n\n\n<li>You can report bugs via&nbsp;<a href=\"https:\/\/github.com\/python\/cpython\/issues\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub Issues<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.python.org\/psf\/donations\/\" target=\"_blank\" rel=\"noreferrer noopener\">Help fund Python and its community<\/a>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to today&#8217;s article on how to install and configure Python 3.12 on Ubuntu 22.04 \/ Ubuntu 20.04 \/ Ubuntu 18.04 Linux system. Our installation is performed from source to ensure we build the latest release of Python 3.12 programming language. Python is an easy to learn and master, interpreted programming language known to simple &#8230; <a title=\"How To Install Python 3.12 on Ubuntu 22.04|20.04|18.04\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/how-to-python-3-12-on-ubuntu-linux\/\" aria-label=\"Read more about How To Install Python 3.12 on Ubuntu 22.04|20.04|18.04\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":152940,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[690,299,50,68,832,81],"tags":[39016],"class_list":["post-152894","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","category-how-to","category-linux-tutorials","category-programming","category-tech","category-ubuntu","tag-python-3-12-on-ubuntu"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/152894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=152894"}],"version-history":[{"count":1,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/152894\/revisions"}],"predecessor-version":[{"id":160644,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/152894\/revisions\/160644"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/152940"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=152894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=152894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=152894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}