{"id":2162,"date":"2023-03-26T13:15:00","date_gmt":"2023-03-26T20:15:00","guid":{"rendered":"https:\/\/ioflood.com\/blog\/?p=2162"},"modified":"2024-01-30T07:28:29","modified_gmt":"2024-01-30T14:28:29","slug":"easily-install-python-3-in-ubuntu","status":"publish","type":"post","link":"https:\/\/ioflood.com\/blog\/easily-install-python-3-in-ubuntu\/","title":{"rendered":"Easily Install Python 3 in Ubuntu"},"content":{"rendered":"\r\n<div class=\"wp-block-image\"><figure class=\"alignright size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2023\/03\/Futuristic_workstation_glowing_holographic_screen_ubuntu_python_halfsize-300x300.jpg\" alt=\"artistic python battleship\" class=\"wp-image-2169\" width=\"300\" height=\"300\" title=\"\" srcset=\"https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2023\/03\/Futuristic_workstation_glowing_holographic_screen_ubuntu_python_halfsize-300x300.jpg 300w, https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2023\/03\/Futuristic_workstation_glowing_holographic_screen_ubuntu_python_halfsize-200x200.jpg 200w, https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2023\/03\/Futuristic_workstation_glowing_holographic_screen_ubuntu_python_halfsize-150x150.jpg 150w, https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2023\/03\/Futuristic_workstation_glowing_holographic_screen_ubuntu_python_halfsize.jpg 512w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\r\n\r\n\r\n\r\n<p>You have a Python script you&#8217;d like to use, but you&#8217;re not sure if your server has Python installed, or if it&#8217;s running the latest version. No problem! We address that common issue in today&#8217;s article. Learn how to install Python 3 in Ubuntu easily in this comprehensive guide.<\/p>\r\n\r\n\r\n\r\n<p>At <a href=\"https:\/\/ioflood.com\">IOFLOOD<\/a>, most of the internal tools we create these days are written in Python. We&#8217;re happy to share the tips and tricks we use to keep our customer&#8217;s <a href=\"https:\/\/ioflood.com\/phoenix-dedicated-servers.php\">dedicated servers<\/a> running smoothly, whether you&#8217;re an IOFLOOD customer or just a curious onlooker.<\/p>\r\n\r\n\r\n\r\n<p>Python is an incredibly versatile programming language with applications ranging from web development to data science and artificial intelligence. It&#8217;s no wonder that Python has become a staple in the software development world. Continue reading to learn step-by-step how to update and install Python on Ubuntu systems.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">TL;DR How to install Python 3 for Ubuntu?<\/h2>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>sudo apt install python3<\/code> is the command that will install your OS&#8217;s default version of Python 3 in Ubuntu. Read the rest of the article for tips on getting the latest version, as well as more advanced installation methods.<\/p><\/blockquote>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Checking if Python is Already Installed<\/h2>\r\n\r\n\r\n\r\n<p>Before installing Python on your installation of Ubuntu, it&#8217;s a good idea to check if Python is already installed. You can do this by running a simple command in the terminal:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ python3 --version<\/pre>\r\n\r\n\r\n\r\n<p>If Python is installed, this command will display the version number. For example, you might see something like:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">Python 3.8.10<\/pre>\r\n\r\n\r\n\r\n<p>If you see a version number, you&#8217;re good to go! Python is already installed on your system. <\/p>\r\n\r\n\r\n\r\n<p>If you want to make sure you have the latest version, check out <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.python.org\/downloads\/<\/a> As of March 24, 2023, the latest stable Python release was 3.11.2.<\/p>\r\n\r\n\r\n\r\n<p>If you&#8217;d like to upgrade versions or you don&#8217;t have Python installed at all, keep reading, we&#8217;ll cover how to install Python in the next section.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Installing Python on Ubuntu<\/h2>\r\n\r\n\r\n\r\n<p>There are several methods to install Python on Ubuntu, including using the APT package manager, Deadsnakes PPA, and installing from source code. We&#8217;ll discuss each of these methods in detail below.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Installing Python using APT<\/h3>\r\n\r\n\r\n\r\n<p>To install Python on Ubuntu, you can make use of the convenient APT (Advanced Package Tool) package manager. We recommend you begin by updating your system&#8217;s package list with the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt update<\/pre>\r\n\r\n\r\n\r\n<p>Next, install Python using the command below. This command will install the latest version of Python 3 available in the Ubuntu repositories:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt install python3<\/pre>\r\n\r\n\r\n\r\n<p>Once the installation is complete, you can verify the installation by checking the Python version again:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ python3 --version<\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Installing Python using Deadsnakes PPA<\/h3>\r\n\r\n\r\n\r\n<p>Another option to install Python on Ubuntu is to use the Deadsnakes PPA (Personal Package Archive). This PPA contains newer versions of Python that may not be available in the official Ubuntu repositories.<\/p>\r\n\r\n\r\n\r\n<p>To install Python using Deadsnakes PPA, first, add the repository to your system:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo add-apt-repository ppa:deadsnakes\/ppa<\/pre>\r\n\r\n\r\n\r\n<p>If you aren&#8217;t able to do this, you may be missing the &#8220;software-properties-common&#8221; dependency, which you can install with this command and then try again:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt install software-properties-common<\/pre>\r\n\r\n\r\n\r\n<p>Update your package list:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt update<\/pre>\r\n\r\n\r\n\r\n<p>And finally, install the desired Python version. For example, to install Python 3.9, run the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt install python3.9<\/pre>\r\n\r\n\r\n\r\n<p>Remember to replace &#8220;3.9&#8221; with the version number you want to install. Reminder, the latest Python release version is listed here: <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.python.org\/downloads\/<\/a><\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Installing Python from source code<\/h2>\r\n\r\n\r\n\r\n<p>This final method or compiling Python from the raw source code offers the most customization and the latest versions. While installing Python from source code offers flexibility in installing a specific Python version, it may not be ideal for beginners due to its complexity and manual work involved.<\/p>\r\n\r\n\r\n\r\n<p>First, install the required build dependencies:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev<\/pre>\r\n\r\n\r\n\r\n<p>Next, download the Python source code from the official website. Replace &#8220;X.Y.Z&#8221; with the desired version number. For example, <em>as of March 24, 2023, the latest version was 3.11.2<\/em><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ curl -O https:\/\/www.python.org\/ftp\/python\/X.Y.Z\/Python-X.Y.Z.tar.xz<\/pre>\r\n\r\n\r\n\r\n<p>Extract the downloaded archive:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ tar -xf Python-X.Y.Z.tar.xz<\/pre>\r\n\r\n\r\n\r\n<p>Change to the extracted directory:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ cd Python-X.Y.Z<\/pre>\r\n\r\n\r\n\r\n<p>Configure the build and install Python:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ .\/configure --enable-optimizations\r\n$ make -j 4\r\n$ sudo make altinstall<\/pre>\r\n\r\n\r\n\r\n<p>Once the installation is complete, you can verify the installation by checking the Python version:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ python3 --version<\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Updating Python to the Latest Version<\/h2>\r\n\r\n\r\n\r\n<p>Keeping your Python installation up-to-date is crucial not only for the latest compatibility with packages and libraries but also for ensuring a secure system. The following are the different ways you can update Python using various installation methods:<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Updating Python using APT<\/h2>\r\n\r\n\r\n\r\n<p>If you installed Python using the APT package manager, you can update it by running the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt update\r\n$ sudo apt upgrade<\/pre>\r\n\r\n\r\n\r\n<p><strong>NOTE:<\/strong> This command will update <em>all<\/em> the packages on your system, including Python. This is generally recommended to make sure that all dependencies are also up to the latest version. If you&#8217;d prefer to update only Python, you can instead run this command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt install --only-upgrade package_name python3<\/pre>\r\n\r\n\r\n\r\n<p>Again, you might want to (or need to) replace &#8220;python3&#8221; with &#8220;python3.X&#8221; where X is the version you have installed currently, such as python3.9.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Updating Python using Deadsnakes PPA<\/h3>\r\n\r\n\r\n\r\n<p>If you installed Python using the Deadsnakes PPA, updating Python is as simple as adding the repository, updating your package list, and upgrading your packages:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo add-apt-repository ppa:deadsnakes\/ppa\r\n$ sudo apt update\r\n$ sudo apt upgrade<\/pre>\r\n\r\n\r\n\r\n<p>Again, please note that this command will update <em>all<\/em> the packages on your system, including Python.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Updating Python from source code<\/h3>\r\n\r\n\r\n\r\n<p>To update Python installed from source code, the process is the same as the installation process. You&#8217;ll need to download the source code of the desired version, extract it, and then execute the configure, make, and make altinstall commands. <\/p>\r\n\r\n\r\n\r\n<p>You can also remove the old version if it&#8217;s no longer necessary. However, some software requires specific Python versions, so you may want to keep multiple versions installed simultaneously to accommodate this.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Running Python on Ubuntu<\/h2>\r\n\r\n\r\n\r\n<p>Python is an immensely popular choice across many industries and applications, ranging from web development to data analysis, and even machine learning. It plays a crucial role in the Linux ecosystem and is often bundled with popular distributions like Ubuntu.<\/p>\r\n\r\n\r\n\r\n<p>To run Python on Ubuntu, simply open a terminal and type &#8220;python3&#8221; followed by the desired version number, if applicable:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ python3<\/pre>\r\n\r\n\r\n\r\n<p>Or:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ python3.9<\/pre>\r\n\r\n\r\n\r\n<p>This command will start the Python interpreter, where you can run Python code interactively. To run a Python script, use the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">$ python3 script.py<\/pre>\r\n\r\n\r\n\r\n<p>Remember to replace &#8220;script.py&#8221; with the path to your Python script.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">More Resources for Python Setups<\/h2>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>> Whether you&#8217;re a beginner or advanced coder, our <a href=\"https:\/\/ioflood.com\/blog\/python-syntax-cheat-sheet\/\">Python syntax cheat sheet<\/a> is an invaluable resource. To enhance your skillsets in Python even further, consider delving into the following learning materials:<\/p><\/blockquote>\r\n\r\n\r\n\r\n1. <a href=\"https:\/\/ioflood.com\/blog\/python-venv-virtual-environment\/\">Python Virtual Environments (venv): Creating Isolated Development Spaces<\/a> &#8211; Learn how to create and manage Python virtual environments using python venv.\r\n<br><br>\r\n2. <a href=\"https:\/\/ioflood.com\/blog\/check-python-version\/\">How to Check Your Python Version: A Quick and Easy Guide<\/a> &#8211; Discover various methods to check the Python version installed on your system.\r\n<br><br>\r\n3. <a href=\"https:\/\/pip.pypa.io\/en\/stable\/installation\/\" target=\"_blank\" rel=\"noopener\">Pip Installation Guide<\/a> &#8211; A step-by-step guide on installing Pip, Python&#8217;s recommended package installer.\r\n<br><br>\r\n4. <a href=\"https:\/\/packaging.python.org\/en\/latest\/tutorials\/installing-packages\/\" target=\"_blank\" rel=\"noopener\">Python Package Installation Tutorial<\/a> &#8211; Learn how to install Python packages to set up your environment effectively.\r\n<br><br>\r\n5. <a href=\"https:\/\/www.python.org\/downloads\/Python\" target=\"_blank\" rel=\"noopener\">Download and Installation<\/a> &#8211; A direct source for downloading and setting up Python on your machine.\r\n<br><br>\r\nBy making use of these resources, you can make Python environment setup and installation a breeze and boost your Python coding efficiency. Remember, a well-organized Python environment can significantly contribute to your productivity and coding comfort.\r\n\r\n\r\n\r\nBy making use of these resources, you can make Python environment setup and installation a breeze and boost your Python coding efficiency. Remember, a well-organized Python environment can significantly contribute to your productivity and coding comfort.\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\r\n\r\n\r\n\r\n<p>This blog has dived right into the ins and outs of checking, installing, and updating Python on Ubuntu systems. We&#8217;ve covered several installation methods, such as APT, Deadsnakes PPA, and source code installation. With a recent and up-to-date version of Python on your system, the doors are now open for you to explore its diverse applications and immerse yourself in the exciting world of programming.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Do you love servers?<\/h2>\r\n\r\n\r\n\r\n<p>We do! Whether you&#8217;re new to programming in Python or you&#8217;re an experienced developer, it helps to have a good home to store and run your code. <a href=\"https:\/\/ioflood.com\">IOFLOOD<\/a> would be happy to help with this! We offer high performance, reliable <a href=\"https:\/\/ioflood.com\/phoenix-dedicated-servers.php\">dedicated servers<\/a> that are ideal for startups who want the best possible systems to run their code on.<\/p>\r\n\r\n\r\n\r\n<p><strong>Email us at sales[at]ioflood.com<\/strong> or view our website at <a href=\"https:\/\/ioflood.com\">https:\/\/ioflood.com<\/a> to learn more about how an IOFLOOD dedicated server could help with your next big project.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>You have a Python script you&#8217;d like to use, but you&#8217;re not sure if your server has Python installed, or if it&#8217;s running the latest version. No problem! We address that common issue in today&#8217;s article. Learn how to install Python 3 in Ubuntu easily in this comprehensive guide. At IOFLOOD, most of the internal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2169,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,121,123,9,6],"tags":[],"class_list":["post-2162","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-programming-coding","category-python","category-sysadmin","category-ubuntu","cat-3-id","cat-121-id","cat-123-id","cat-9-id","cat-6-id","has_thumb"],"_links":{"self":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/2162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/comments?post=2162"}],"version-history":[{"count":29,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/2162\/revisions"}],"predecessor-version":[{"id":2207,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/2162\/revisions\/2207"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media\/2169"}],"wp:attachment":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media?parent=2162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/categories?post=2162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/tags?post=2162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}