{"id":99953,"date":"2026-02-03T17:20:18","date_gmt":"2026-02-03T11:50:18","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=99953"},"modified":"2026-02-03T17:20:22","modified_gmt":"2026-02-03T11:50:22","slug":"how-to-install-python-in-ubuntu","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/how-to-install-python-in-ubuntu\/","title":{"rendered":"How to Install Python in Ubuntu: A Beginner&#8217;s Guide That Actually Works"},"content":{"rendered":"\n<p>Python ranks as the most popular programming language today according to the TIOBE Index, making it essential to know how to install Python in Ubuntu if you&#8217;re entering the world of programming.<\/p>\n\n\n\n<p>You might be surprised to learn that Python 3 typically comes pre-installed on most Ubuntu versions, especially in 20.04, 22.04, and 24.04. However, understanding how to properly install, update, or manage different Python versions is still a valuable skill. Created by Guido van Rossum in 1990 and named after the comedy &#8220;Monty Python&#8217;s Flying Circus,&#8221; this ubiquitous object-oriented scripting language features an extensive ecosystem that powers countless applications worldwide.<\/p>\n\n\n\n<p>This beginner-friendly guide will walk you through installing Python in Ubuntu, checking existing installations, and setting up your first Python environment. We&#8217;ll keep everything simple and straightforward, focusing on practical steps that actually work for beginners. Let\u2019s begin!<\/p>\n\n\n\n<p><strong>Quick Answer:<\/strong><\/p>\n\n\n\n<p>Python usually comes pre-installed on Ubuntu, but learning how to check, install, and manage Python versions properly ensures a stable system and a smoother start to programming.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Getting Started With Python in Ubuntu<\/strong><\/h2>\n\n\n\n<p>When you first boot up your Ubuntu system, you might not realize that <a href=\"https:\/\/www.guvi.in\/hub\/python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a> is already there, ready to use. Unlike many programming tools that require manual installation, Python comes bundled with your operating system. Let&#8217;s explore why this is the case and how to verify your Python installation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1) Why Python is Pre-Installed on Most Ubuntu Versions<\/strong><\/h3>\n\n\n\n<p>Python plays a crucial role in Ubuntu&#8217;s core functionality. Many system tools and applications depend on Python to operate properly. Ubuntu developers include Python by default because it powers numerous background processes essential to your operating system.<\/p>\n\n\n\n<p>Each <a href=\"https:\/\/ftp.guvi.in\/hub\/linux-guide-tutorial\/check-ubuntu-version\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu<\/a> release comes with a specific Python version:<\/p>\n\n\n\n<ul>\n<li>Ubuntu 24.04 (Noble) includes Python 3.12<\/li>\n\n\n\n<li>Ubuntu 22.04 (Jammy) ships with Python 3.10<\/li>\n\n\n\n<li>Ubuntu 20.04 (Focal) includes Python 3.8<\/li>\n<\/ul>\n\n\n\n<p>Most importantly, experts strongly recommend not tampering with the system&#8217;s pre-installed Python version. Modifying or removing this installation can potentially break critical operating system functionalities. As one document notes, &#8220;if you mess up Python, it might break Ubuntu&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2) How to Check if Python is Installed<\/strong><\/h3>\n\n\n\n<p>Before attempting to <a href=\"https:\/\/www.guvi.in\/hub\/python\/how-to-install-python-on-windows\/\" target=\"_blank\" rel=\"noreferrer noopener\">install Python<\/a>, first verify whether it&#8217;s already available on your system. Checking is straightforward using the terminal:<\/p>\n\n\n\n<p>Press Ctrl+Alt+T to open the terminal<\/p>\n\n\n\n<p>Type one of these commands:<br>python3 &#8211;version<\/p>\n\n\n\n<p>or the shorter version:<br>python3 -V<\/p>\n\n\n\n<p>The terminal will display your Python version. For example, on Ubuntu 22.04, you might see:<\/p>\n\n\n\n<p>Python 3.10.0<\/p>\n\n\n\n<p>Additionally, you can check if a specific Python version is installed by explicitly mentioning the version number:<\/p>\n\n\n\n<p>python3.12 &#8211;version<\/p>\n\n\n\n<p>If Python is installed, these commands will return version information. If not, you&#8217;ll receive an error message indicating the command wasn&#8217;t found.<\/p>\n\n\n\n<p>Furthermore, it&#8217;s worth noting that older Ubuntu installations might have both Python 2 and Python 3. To check for Python 2 (though it&#8217;s largely deprecated now), you can use:<\/p>\n\n\n\n<p>python &#8211;version<\/p>\n\n\n\n<p>Now that you&#8217;ve confirmed your Python installation status, you&#8217;re ready to move forward with installation if needed or jump straight to writing your first Python program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Install Python the Right Way<\/strong><\/h2>\n\n\n\n<p>While Ubuntu typically comes with Python pre-installed, there are several methods to install specific versions based on your needs. Let&#8217;s explore the most effective approaches to install Python in Ubuntu properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1) Using apt to install Python 3<\/strong><\/h3>\n\n\n\n<p>The simplest way to install Python in Ubuntu is through the default package manager, apt. This method is ideal for beginners seeking the standard version available in Ubuntu repositories.<\/p>\n\n\n\n<p>To install Python using apt:<\/p>\n\n\n\n<p>sudo apt update<\/p>\n\n\n\n<p>sudo apt install python3<\/p>\n\n\n\n<p>After installation, verify by typing:<\/p>\n\n\n\n<p>python3 &#8211;version<\/p>\n\n\n\n<p>Moreover, you can install essential Python tools alongside:<\/p>\n\n\n\n<p>sudo apt install python3-pip python3-venv<\/p>\n\n\n\n<p>This approach is straightforward but has limitations \u2013 primarily that you&#8217;ll only get the default Python version for your Ubuntu release.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2) Installing a Specific Version Using PPA<\/strong><\/h3>\n\n\n\n<p>For accessing newer or older Python versions than what&#8217;s available in standard repositories, the Deadsnakes PPA (Personal Package Archive) is an excellent solution.<\/p>\n\n\n\n<p>Initially, install prerequisites:<\/p>\n\n\n\n<p>sudo apt install software-properties-common<\/p>\n\n\n\n<p>sudo add-apt-repository ppa:deadsnakes\/ppa<\/p>\n\n\n\n<p>sudo apt update<\/p>\n\n\n\n<p>Then install your desired Python version:<\/p>\n\n\n\n<p>sudo apt install python3.12<\/p>\n\n\n\n<p>Replace &#8220;3.12&#8221; with your preferred version. Consequently, this method doesn&#8217;t overwrite your system Python, which is crucial for system stability. Each version installs side-by-side, accessible via its specific command (e.g., python3.12).<\/p>\n\n\n\n<p>To switch between versions, you can use the update-alternatives command:<\/p>\n\n\n\n<p>sudo update-alternatives &#8211;install \/usr\/bin\/python3 python3 \/usr\/bin\/python3.8 1<\/p>\n\n\n\n<p>sudo update-alternatives &#8211;install \/usr\/bin\/python3 python3 \/usr\/local\/bin\/python3.9 2<\/p>\n\n\n\n<p>Followed by:<\/p>\n\n\n\n<p>sudo update-alternatives &#8211;config python3<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3) Installing From Source (Advanced Users)<\/strong><\/h3>\n\n\n\n<p>Alternatively, advanced users might prefer compiling Python from source code for the latest features or specific optimizations.<\/p>\n\n\n\n<p>First, install dependencies:<\/p>\n\n\n\n<p>sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget<\/p>\n\n\n\n<p>Download and extract the source:<\/p>\n\n\n\n<p>wget https:\/\/www.python.org\/ftp\/python\/3.12.1\/Python-3.12.1.tgz<\/p>\n\n\n\n<p>tar -xf Python-3.12.1.tgz<\/p>\n\n\n\n<p>Configure and build:<\/p>\n\n\n\n<p>cd Python-3.12.1<\/p>\n\n\n\n<p>.\/configure &#8211;enable-optimizations<\/p>\n\n\n\n<p>sudo make altinstall<\/p>\n\n\n\n<p>The &#8211;enable-optimizations flag improves performance by 10-20%. Using altinstall preserves your system Python installation, avoiding potential system breakage.<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\">\n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong> \n  <br \/><br \/> \nTo keep things interesting, here are a couple of simple facts about Python and Ubuntu that many beginners don\u2019t realize:\n<br \/><br \/> \n<strong>Ubuntu Depends on Python Internally:<\/strong> Several core Ubuntu tools and system utilities are written in Python, which is why Python comes pre-installed and why removing it can break your system.\n<br \/><br \/> \n<strong>Multiple Python Versions Can Coexist Safely:<\/strong> Ubuntu allows you to install multiple Python versions side by side, letting developers test and run different projects without affecting the system Python.\n<br \/><br \/> \nThese facts explain why Python feels so tightly integrated with Ubuntu and why managing it correctly is an important beginner skill.\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Running Your First Python Program<\/strong><\/h2>\n\n\n\n<p>After successfully installing Python in your Ubuntu system, the next exciting step is to run your <a href=\"https:\/\/www.guvi.in\/hub\/python-tutorial\/syntax-rules-and-first-program\/\" target=\"_blank\" rel=\"noreferrer noopener\">first program<\/a>. Let&#8217;s explore different methods to execute Python code on your Ubuntu machine.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1) Using the Terminal to Run Python Scripts<\/strong><\/h3>\n\n\n\n<p>The terminal offers a straightforward approach to run Python scripts. First, you need to create a Python file with the .py extension. Once your file is ready, follow these simple steps:<\/p>\n\n\n\n<ol>\n<li>Open your terminal by pressing Ctrl+Alt+T<\/li>\n\n\n\n<li>Navigate to your file&#8217;s directory using the cd command<\/li>\n\n\n\n<li>Run your script with: python3 yourscript.py<\/li>\n<\/ol>\n\n\n\n<p>For frequent usage, you can make your Python script executable:<\/p>\n\n\n\n<p>chmod +x yourscript.py<\/p>\n\n\n\n<p>Next, add a shebang line at the top of your script:<\/p>\n\n\n\n<p><em>#!\/usr\/bin\/env python3<\/em><\/p>\n\n\n\n<p>Subsequently, you can run the script directly with:<\/p>\n\n\n\n<p>.\/yourscript.py<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2) Using IDLE to Write and Run Code<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/hub\/python-tutorial\/introduction-to-idle\/\" target=\"_blank\" rel=\"noreferrer noopener\">IDLE (Integrated Development and Learning Environment)<\/a> is Python&#8217;s official beginner-friendly IDE. To install IDLE on Ubuntu:<\/p>\n\n\n\n<p>sudo apt-get install idle3<\/p>\n\n\n\n<p>Upon installation, launch IDLE by typing idle3 in your terminal or finding it in your applications menu. IDLE provides two main windows:<\/p>\n\n\n\n<ul>\n<li><strong>The Shell Window:<\/strong> For interactive Python coding<\/li>\n\n\n\n<li><strong>The Editor Window:<\/strong> For writing longer programs<\/li>\n<\/ul>\n\n\n\n<p>To open a new file, select File &gt; New File. After writing your code, save it with File &gt; Save As, then run it by pressing F5 or selecting Run &gt; Run Module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3) Creating a Hello World Script<\/strong><\/h3>\n\n\n\n<p>Creating your first &#8220;Hello World&#8221; program is remarkably simple. In your terminal or IDLE editor, create a file named hello.py and write:<\/p>\n\n\n\n<p>print(&#8220;Hello, World!&#8221;)<\/p>\n\n\n\n<p>This single line tells Python to display the text &#8220;Hello, World!&#8221; on your screen. The print() function outputs whatever is inside the parentheses.<\/p>\n\n\n\n<p>Running this script will confirm your Python installation is working properly. From this starting point, you can gradually build more complex programs as you continue learning Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Next Steps After Installation<\/strong><\/h2>\n\n\n\n<p>Congratulations on setting up Python! Once installed, it&#8217;s time to enhance your setup with tools that help you develop better code. Following these next steps will turn your basic installation into a complete Python development environment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1) Set up pip and Virtual Environments<\/strong><\/h3>\n\n\n\n<p>Pip is the package management system for installing Python libraries and tools from the Python Package Index (PyPI). To install pip, run:<\/p>\n\n\n\n<p>sudo apt install python3-pip<\/p>\n\n\n\n<p>Likewise, virtual environments are essential for creating isolated spaces where each project has its own dependencies. First, install the required package:<\/p>\n\n\n\n<p>sudo apt install python3-venv<\/p>\n\n\n\n<p>Create a virtual environment with:<\/p>\n\n\n\n<p>python3 -m venv .venv<\/p>\n\n\n\n<p>Activate it using:<\/p>\n\n\n\n<p>source .venv\/bin\/activate<\/p>\n\n\n\n<p>Virtual environments primarily help separate your development projects from the system Python installation, preventing potential conflicts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2) Follow Python Style Guide (PEP 8)<\/strong><\/h3>\n\n\n\n<p>PEP 8, written by Python&#8217;s creator Guido van Rossum and others, serves as the official style guide for Python code. It emphasizes readability through:<\/p>\n\n\n\n<ul>\n<li>Using 4 spaces for indentation (not tabs)<\/li>\n\n\n\n<li>Limiting lines to 79 characters maximum<\/li>\n\n\n\n<li>Following naming conventions (snake_case for variables\/functions)<\/li>\n\n\n\n<li>Organizing imports logically<\/li>\n\n\n\n<li>Adding appropriate whitespace<\/li>\n<\/ul>\n\n\n\n<p>Adhering to PEP 8 makes your code more professional and easier for others to read.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3) Explore Learning Resources and Tutorials<\/strong><\/h3>\n\n\n\n<p>To continue your Python journey, check out these valuable resources:<\/p>\n\n\n\n<ul>\n<li>Python&#8217;s official website (<a href=\"http:\/\/python.org\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">python.org<\/a>)<\/li>\n\n\n\n<li>HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/courses\/programming\/python\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=How+to+Install+Python+in+Ubuntu%3A+A+Beginner%27s+Guide+That+Actually+Works\" target=\"_blank\" rel=\"noreferrer noopener\">Python Course<\/a><\/li>\n\n\n\n<li>Core Python Learning Path on Pluralsight<\/li>\n\n\n\n<li>Python for Linux System Administration guides<\/li>\n\n\n\n<li>Interactive Python interpreters like bpython<\/li>\n<\/ul>\n\n\n\n<p>These resources offer structured learning paths that build upon your new Ubuntu Python installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Concluding Thoughts\u2026<\/strong><\/h2>\n\n\n\n<p>Installing Python in Ubuntu might seem intimidating at first, especially for beginners. Nevertheless, as you&#8217;ve seen throughout this guide, the process can be straightforward when approached correctly. Python typically comes pre-installed on most Ubuntu distributions, which saves you considerable time and effort when starting your programming journey.<\/p>\n\n\n\n<p>Beyond installation, your Python journey has only just begun. The &#8220;Hello World&#8221; script represents your first step into a vast ecosystem of possibilities. Python&#8217;s versatility allows you to explore web development, data science, artificial intelligence, and countless other fields.<\/p>\n\n\n\n<p>Therefore, take what you&#8217;ve learned about installing Python in Ubuntu and build upon this foundation. The programming world awaits your creativity, and Python offers one of the most accessible entry points into this exciting field. Start small, practice regularly, and soon you&#8217;ll develop the skills to create increasingly complex applications on your Ubuntu system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1769952891896\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q1. Is Python pre-installed on Ubuntu?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, Python typically comes pre-installed on most Ubuntu versions. For example, Ubuntu 22.04 ships with Python 3.10, while Ubuntu 20.04 includes Python 3.8. However, it&#8217;s important to note that you shouldn&#8217;t modify or remove the system&#8217;s pre-installed Python version as it could potentially break critical operating system functionalities.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1769952898737\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q2. How can I check which version of Python is installed on my Ubuntu system?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>To check your Python version, open the terminal and type either &#8220;python3 &#8211;version&#8221; or &#8220;python3 -V&#8221;. This will display the version of Python currently installed on your system. You can also check for specific versions by using the command &#8220;python3.x &#8211;version&#8221;, replacing x with the version number you&#8217;re looking for.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1769952915548\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q3. What&#8217;s the easiest way to install a different version of Python in Ubuntu?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The simplest method to install a different Python version on Ubuntu is by using the Deadsnakes PPA (Personal Package Archive). First, add the PPA to your system, update the package list, and then install the desired Python version using apt. For example, to install Python 3.12, you would use the command &#8220;sudo apt install python3.12&#8221; after setting up the PPA.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1769952930959\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q4. How do I run my first Python program on Ubuntu?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>To run your first Python program, create a file with a .py extension (e.g., hello.py) containing your Python code. Open a terminal, navigate to the directory containing your file, and run it using the command &#8220;python3 yourscript.py&#8221;. Alternatively, you can use IDLE, Python&#8217;s built-in development environment, to write and run your code.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1769952945536\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Q5. What are some essential next steps after installing Python in Ubuntu?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>After installing Python, it&#8217;s recommended to set up pip (Python&#8217;s package manager) and virtual environments. Install pip using &#8220;sudo apt install python3-pip&#8221;. For virtual environments, install the package with &#8220;sudo apt install python3-venv&#8221;. It&#8217;s also beneficial to familiarize yourself with the Python style guide (PEP 8) for writing clean, readable code. Lastly, explore various learning resources and tutorials to continue developing your Python skills.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Python ranks as the most popular programming language today according to the TIOBE Index, making it essential to know how to install Python in Ubuntu if you&#8217;re entering the world of programming. You might be surprised to learn that Python 3 typically comes pre-installed on most Ubuntu versions, especially in 20.04, 22.04, and 24.04. However, [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":100112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[717],"tags":[],"views":"612","authorinfo":{"name":"Jaishree Tomar","url":"https:\/\/www.guvi.in\/blog\/author\/jaishree\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/02\/python-in-ubuntu-300x112.webp","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/02\/python-in-ubuntu.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/99953"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=99953"}],"version-history":[{"count":5,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/99953\/revisions"}],"predecessor-version":[{"id":100161,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/99953\/revisions\/100161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/100112"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=99953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=99953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=99953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}