{"id":5181,"date":"2021-03-18T10:14:59","date_gmt":"2021-03-18T10:14:59","guid":{"rendered":"https:\/\/linuxways.net\/?p=5181"},"modified":"2021-03-18T10:14:59","modified_gmt":"2021-03-18T10:14:59","slug":"how-to-install-python-3-9-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-python-3-9-on-ubuntu-20-04\/","title":{"rendered":"How to Install Python 3.9 on Ubuntu 20.04"},"content":{"rendered":"<p>If you\u2019re using Ubuntu Linux, chances are you will be using some if not many, python-based applications.<\/p>\n<p>Python is a simple to use, easy learning programming language and ranks as one of the top most popular programming languages.<\/p>\n<p>Python is a programming language known for its easy syntax. It is one of the best and most commonly used languages for machine learning and AI software.<\/p>\n<p>In this article, you will learn how to install Python 3.9 on Ubuntu 20.04 from a PPA repository, compile it from source code and alternatively compile and install it using Linuxbrew tool.<\/p>\n<p>The same steps apply for all Ubuntu-based distribution, like Linux Mint and Elementary OS, and also including other Ubuntu flavors like Kubuntu and previous Ubuntu releases.<\/p>\n<h2>Installing Python 3.9 on Ubuntu using APT<\/h2>\n<p>By default, Ubuntu 20.04 comes with Python 3.8 installed.<\/p>\n<p>You can check that out by typing:<\/p>\n<pre>$ python3 --version<\/pre>\n<p>Python 3.8.5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5182\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-265.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-265.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-265-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-265-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-265-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-265-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>Now, we will see how to install Python 3.9 from the PPA repository. It is a pretty easy and straightforward process to complete.<\/p>\n<p>First, we will update the system:<\/p>\n<pre>$ sudo apt update &amp;&amp; sudo apt upgrade<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5183\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-266.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-266.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-266-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-266-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-266-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-266-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>Before adding the Python Ubuntu repository, we need to install the software-properties-common package to manage independent software vendor software sources.<\/p>\n<pre>$ sudo apt install software-properties-common<\/pre>\n<p>Now add the repository to the system\u2019s repository list:<\/p>\n<pre>$ sudo add-apt-repository ppa:deadsnakes\/ppa<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5184\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-267.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-267.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-267-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-267-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-267-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-267-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>You\u2019ll see the text info about PPA repository and prompt to continue. Now press the enter to continue, and add the new repository. You should see the newly added repo deadsnakes in the output at the end:<\/p>\n<p>Get:1 http:\/\/ppa.launchpad.net\/deadsnakes\/ppa\/ubuntu focal InRelease [18.1 kB]<\/p>\n<p>Once the repository is added, you can install Python 3.9 simply by executing:<\/p>\n<pre>$ sudo apt install python3.9<\/pre>\n<p>We can verify that the operation was successful by running:<\/p>\n<pre>$ python3.9 --version<\/pre>\n<p>Python 3.9.1<\/p>\n<p>The following command can help you identify the install location of Python executable binary:<\/p>\n<pre>$ which python3.9<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5185\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-268.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-268.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-268-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-268-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-268-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-268-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<h2>Install Python 3.9.1 on Ubuntu 20.04 from Source Code<\/h2>\n<p>Now we will see how to compile Python from the source code. When you compile Python from the source code, you can install the latest version of the application and customize the build options.<\/p>\n<p>First, we must install the required build dependencies by installing the following APT packages:<\/p>\n<pre>$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5186\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-269.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-269.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-269-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-269-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-269-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-269-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>Next, download the latest source code archive using wget tool:<\/p>\n<pre>$ wget <a href=\"https:\/\/www.python.org\/ftp\/python\/3.9.1\/Python-3.9.1.tgz\">https:\/\/www.python.org\/ftp\/python\/3.9.1\/Python-3.9.1.tgz<\/a><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5187\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-270.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-270.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-270-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-270-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-270-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-270-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>Now, extract the downloaded archive:<\/p>\n<pre>$ tar -xf Python-3.9.1.tgz<\/pre>\n<p>Enter the Python-3.9.1 directory and run the configuration script as follows.<\/p>\n<pre>$ cd Python-3.9.1<\/pre>\n<pre>$ .\/configure \u2013enable-optimizations<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5188\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-271.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-271.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-271-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-271-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-271-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-271-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>When the script is finished, run the make command to compile the binary executable:<\/p>\n<pre>$ make -j 8<\/pre>\n<p>If you have more than 8 cores on your computer, you can adjust the above command (-j parameter) to reflect the number of your CPU cores for faster build time. You can use nproc command to see how many processor cores you have on your machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5189\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-272.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-272.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-272-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-272-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-272-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-272-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>When the compilation is completed, install the binary file using:<\/p>\n<pre>$ sudo make altinstall<\/pre>\n<p>We use altinstall in this case because if the install parameter is used, the installation process will overwrite the default Python3 system binary.<\/p>\n<p>When the installation operation is finished, you can check the location of the binary file with:<\/p>\n<pre>$ which python3.9<\/pre>\n<p>\/usr\/local\/bin\/python3.9<\/p>\n<p>We can see that Python 3.9 has been installed on your Linux system.<\/p>\n<h2>Install Python 3.9.1 on Ubuntu 20.04 <strong>with<\/strong> <strong>Linuxbrew (HomeBrew)<\/strong><\/h2>\n<p>To install Linuxbrew, type the following in the terminal:<\/p>\n<pre>$ \/bin\/bash -c \"$(curl -fsSL <a href=\"https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh\">https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh<\/a>)\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5190\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-273.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-273.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-273-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-273-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-273-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-273-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>Next, add Linuxbrew to your PATH in \/home\/USERNAME\/.profile (change USERNAME in command with your logged-in user):<\/p>\n<pre>$ echo 'eval $(\/home\/linuxbrew\/.linuxbrew\/bin\/brew shellenv)' &gt;&gt; \/home\/USERNAME\/.profile<\/pre>\n<pre>$ eval $(\/home\/linuxbrew\/.linuxbrew\/bin\/brew shellenv)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5191\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-274.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-274.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-274-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-274-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-274-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-274-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>Next, install Python 3.9 by running this command:<\/p>\n<pre>$ brew install python@3.9<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1872\" height=\"1032\" class=\"wp-image-5192\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-275.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-275.png 1872w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-275-300x165.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-275-1024x565.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-275-768x423.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/03\/word-image-275-1536x847.png 1536w\" sizes=\"auto, (max-width: 1872px) 100vw, 1872px\" \/><\/p>\n<p>After some time, we will see this log at the end:<\/p>\n<p>==&gt; python@3.9<\/p>\n<p>Python has been installed as<\/p>\n<p>\/home\/linuxbrew\/.linuxbrew\/bin\/python3<\/p>\n<p>See: <a href=\"https:\/\/docs.brew.sh\/Homebrew-and-Python\">https:\/\/docs.brew.sh\/Homebrew-and-Python<\/a><\/p>\n<p>We have successfully installed the latest python3.9 using Linuxbrew. This is the simplest method to install it.<\/p>\n<p>We can also check and verify the installation directory:<\/p>\n<pre>$ which python3<\/pre>\n<p>\/home\/linuxbrew\/.linuxbrew\/bin\/python3<\/p>\n<h2>Conclusion<\/h2>\n<p>We have successfully installed and compiled Python3.9 using three different methods, using PPA repo, compiling it from the source code, and installing it using the Linuxbrew tool. We can now start using Python 3.9 for our projects.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you\u2019re using Ubuntu Linux, chances are you will be using some if not many, python-based applications. Python is a simple to use, easy learning programming language and&hellip;<\/p>","protected":false},"author":1,"featured_media":5266,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[231,10,100],"class_list":["post-5181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-linuxbrew","tag-python","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/5181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=5181"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/5181\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/5266"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=5181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=5181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=5181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}