Skip to content
    geeksforgeeks
    • Interview Prep
      • DSA
      • Interview Corner
      • Aptitude & Reasoning
      • Practice Coding Problems
      • All Courses
    • Tutorials
      • Python
      • Java
      • ML & Data Science
      • Programming Languages
      • Web Development
      • CS Subjects
      • DevOps
      • Software and Tools
      • School Learning
    • Tracks
      • Languages
        • Python
        • C
        • C++
        • Java
        • Advanced Java
        • SQL
        • JavaScript
        • C#
      • Interview Preparation
        • GfG 160
        • GfG 360
        • System Design
        • Core Subjects
        • Interview Questions
        • Interview Puzzles
        • Aptitude and Reasoning
        • Product Management
        • Computer Organisation and Architecture
      • Data Science
        • Python
        • Data Analytics
        • Complete Data Science
        • Gen AI
        • Agentic AI
      • Dev Skills
        • Full-Stack Web Dev
        • DevOps
        • Software Testing
        • CyberSecurity
        • NextJS
        • Git
      • Tools
        • Computer Fundamentals
        • AI Tools
        • MS Excel & Google Sheets
        • MS Word & Google Docs
      • Maths
        • Maths For Computer Science
        • Engineering Mathematics
        • School Maths
    • Python Tutorial
    • Data Types
    • Interview Questions
    • Examples
    • Quizzes
    • DSA Python
    • Data Science
    • NumPy
    • Pandas
    • Practice
    • Django
    • Flask
    • Projects
    Open In App

    How to Install Python on Linux

    Last Updated : 12 Jul, 2025
    Comments
    Improve
    Suggest changes
    8 Likes
    Like
    Report

    This guide explains how to install Python on Linux machines. Python has become an essential programming language for developers, data scientists, and system administrators. It's used for various applications, including web development, data science, automation, and machine learning.

    This comprehensive guide will walk you through the process of installing Python on your Linux system, covering everything from basic package management to advanced installation methods.

    How-to-Install-Python-on-Linux
    All Methods to Install Python on Linux

    Table of Content

    • Major Versions of Python
    • First, Check if Python is Already Installed on Linux
    • Method 1: Installing Python using Package Managers (For Beginners)
    • Method 2: Installing Python Using Version Managers (For Developers)
    • Method 3: Manual Installation Methods for Python on Linux
    • Method 4: Installing Python on Linux Using Cloud-Based Solutions

    Major Versions of Python

    When installing Python, it’s important to understand the two major versions:

    • Python 2: A legacy version no longer maintained. Avoid using it for new projects.
    • Python 3: The actively maintained version with enhanced features. Ideal for modern applications.

    Tip: Always prioritize Python 3 for new projects.

    Pre-Installation Checklist

    Before starting the installation process, ensure you have:

    1. Root Access: Sudo privileges to install software.
    2. Terminal Access: Familiarity with the command line.
    3. Internet Connection: Active internet access for downloading packages.
    4. Disk Space: At least 200MB available.
    5. Command-Line Basics: Understanding of simple terminal commands.

    First, Check if Python is Already Installed on Linux

    Many Linux distributions come with Python pre-installed. Knowing if Python is pre-installed saves time and avoids duplicate installations.

    Note: If Python is installed, the terminal will display its version number. If not, the terminal will return a "command not found" error, indicating that Python needs to be installed.

    Step 1: Open Terminal

    Open your terminal window using the shortcut key Ctrl + Alt + T

    Step 2: Check for Python Version

    For Python 3

    Use the following command to verify the Pre-Installed Python 3 Version in your Linux Laptiop.

    python3 --version

    For Python 2

    Use the following command to check the Pre-Installed Python 2 Version in your Linux Environment.

    python --version

    Method 1: Installing Python using Package Managers (For Beginners)

    This the simplest and most common method of installing Python. Package managers are essential tools in Linux distributions that handle the installation, upgrading, and removal of software packages. Each Linux distribution has its preferred package manager.

    Installing Python For Ubuntu/Debian Based Systems using APT

    APT (Advanced Package Tool) is the default package manager for Ubuntu and Debian-based systems, known for its Extensive package repository, Strong security features, Stable package versions, and Regular security updates.

    Step 1: Update Package Repository

    Note: Always start with this step to prevent version conflicts.

    The following command will refreshes your system's package database to ensure you get the latest version.

    sudo apt update

    Step 2: Upgrade Existing Packages

    Note: This step prevents compatibility issues by updating all installed software.

    Updates all installed packages to their latest versions.

    sudo apt upgrade

    Step 3: Install Python 3

    This commands Installs the default Python 3 version for your.

    sudo apt install python3

    Step 4: Install Python Package Manager (pip)

    Pip is essential for managing Python libraries and dependencies. This command Installs pip for managing Python packages and dependencies.

    sudo apt install python3-pip

    Step 5: Install Additional Tools for Development

    Provides tools for creating virtual environments and compiling Python extensions.

    sudo apt install python3-dev python3-venv build-essential

    Errors and Fixes

    Permission Denied Errors

    This command will Fixe common permission issues with pip installations.

    sudo chown -R $USER:$USER ~/.local

    Package Lock Errors

    This command Resolves package manager lock issues.

    sudo rm /var/lib/apt/lists/lock
    sudo rm /var/cache/apt/archives/lock

    Set up Python For Fedora Linux Systems using DNF

    DNF (Dandified Yum) is the next-generation package manager for Red Hat-based systems, including Fedora, CentOS, and RHEL. Known for its enhanced performance, DNF is particularly effective for managing dependencies and ensuring system stability.

    Step 1: Update System Package List

    The following command will refreshes your system's package database to ensure you get the latest version.

    sudo dnf update

    Step 2: Install Python 3

    This commands Installs the default Python version with necessary dependencies.

    sudo dnf install python3

    Step 3: Install Development Tools

    This commands Installs compilers and libraries required for Python development.

    sudo dnf groupinstall "Development Tools"

    Step 4: Install pip

    This command installs Installs the Python package manager.

    sudo dnf install python3-pip

    Erros and Fixes: Red Hat/Fedora Systems

    Slow Downloads: If DNF is slow

    This command Improves download speed by increasing parallel connections.

    echo 'max_parallel_downloads=10' | sudo tee -a /etc/dnf/dnf.conf

    Repository Issues on CentOS

    This Resolves issues with outdated or misconfigured repositories.

    sudo yum clean all
    sudo yum repolist

    How to Install Latest Python on Arch Linux using Pacman

    Pacman is the default package manager for Arch Linux, offering a rolling release model, Latest software versions, Simple and fast package management, and Minimal overhead.

    Step 1: Update System

    Synchronizes package repositories and updates your system.

    sudo pacman -Syu

    Step 2: Install Python

    Installs the latest available Python version.

    sudo pacman -S python

    Step 3: Install pip

    Adds pip for Python library management.

    sudo pacman -S python-pip

    Errors and Fixes: Red Hat/Fedora Systems

    Package Conflicts

    Removes conflicting packages safely.

    sudo pacman -Rns conflicting-package

    How to install Python on CentOS and Red Hat Linux

    YUM offers Enterprise-grade stability, Long-term support, Extensive documentation, Commercial support options.

    Step 1: Update System

    Updates the package database and installed packages.

    sudo yum update

    Step 2: Enable EPEL Repository

    Enables Extra Packages for Enterprise Linux repository.

    sudo yum install epel-release

    Step 3: Install Python 3

    Installs Python 3 from the repository.

    sudo yum install python3

    Errors and Fixes: CentOS/RHEL Using YUM

    Repository Issues: Cleans and verifies repository configuration.

    sudo yum clean all
    sudo yum repolist

    Installing Newest Python on openSUSE using Zypper

    Zypper provides Advanced package management, Strong dependency resolution, Integration with YaST, and Enterprise support options.

    Step 1: Update Repositories

    Updates package repository information.

    sudo zypper refresh

    Step 2: Install Python

    Installs Python 3 and basic dependencies.

    sudo zypper install python3

    Step 3: Install Development Tools

    Installs Python development files.

    sudo zypper install python3-devel

    Fixes and Errors: openSUSE Using Zypper

    Repository Conflicts: Resolves repository and cache issues.

    sudo zypper clean
    sudo zypper refresh

    Best Practices When Intsalling Python on Linux

    • Always Update First Before installing Python, update your system's package database and existing packages.
    • After installation, verify Python and pip are correctly installed.

    Method 2: Installing Python Using Version Managers (For Developers)

    Python Version managers like Pyenv and asdf are for developers who need to work with multiple Python versions. This provide the flexibility to switch between different Python versions easily, creating isolated environments, and managing project-specific dependencies effectively.

    Install Latest Python Version with Pyenv

    Pyenv is a lightweight Python version management tool which is popular among developers, as it manages multiple Python versions easily.

    Step 1: Install Dependencies

    It Provides libraries required to compile Python.

    sudo apt install -y build-essential libssl-dev zlib1g-dev \

    libsqlite3-dev libffi-dev

    Step 2: Install Pyenv

    Downloads and installs Pyenv on your system.

    curl https://pyenv.run/ | bash

    This command installs Pyenv along with useful plugins like pyenv-virtualenv and pyenv-update.

    Step 3: Configure Shell Environment

    Sets up your shell environment to work with pyenv.

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc

    echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

    echo 'eval "$(pyenv init -)"' >> ~/.bashrc

    Step 4: Reload Shell Configuration

    Activates the new shell configuration.

    source ~/.bashrc

    Step 5: Install Python

    To see a list of available Python versions, run:

    pyenv install --list

    Choose a version you want to install (e.g., Python 3.13.1) and run:

    pyenv install -v 3.13.1

    The -v flag enables verbose mode, showing detailed output during installation

    Step 6: Set Global or Local Python Version

    After installation, you can set the global Python version that will be used by default:

    pyenv global <version>

    Alternatively, you can set a local version for a specific project directory:

    pyenv local <version>

    Step 7: Verify Installation

    To confirm that the installation was successful, check the installed version of Python:

    python --version

    Errors and Fixes: Pyenv Installation and Setup for Python Installation

    Build Failures: Resolves common build optimization issues.

    CFLAGS="-O2" pyenv install 3.12.1

    SSL Errors: Fixes SSL-related installation problems.

    sudo apt install libssl-dev

    Install Python using asdf on Linux System

    asdf is a versatile version manager that allows you to manage multiple versions of various programming languages, including Python. Here’s how to install Python using asdf on a Linux system:

    Step 1: Install asdf

    1. Install Dependencies

    Ensure you have git and curl installed on your system. You can install them using your package manager.

    sudo apt update
    sudo apt install git curl

    2. Clone the asdf Repository

    Open your terminal and run:

    git clone https://github.com/asdf-vm/asdf ~/.asdf --branch v0.13.1

    Step 2: Configure the Shell

    Add the following lines to your shell configuration file (e.g., ~/.bashrc or ~/.zshrc):

    . "$HOME/.asdf/asdf.sh"
    . "$HOME/.asdf/completions/asdf.bash"  (for bash users)

    For Zsh users, replace .bash with .zsh

    Step 3: Install the Python Plugin

    asdf plugin-add python

    Step 4: Reload Your Shell

    Run the following command to apply the changes:

    source ~/.bashrc  # or source ~/.zshrc for Zsh users

    Step 5: Install the Python Plugin

    Run the following command to add the Python plugin to asdf:

    asdf plugin-add python

    Step 6: Install Python Versions

    1. List available versions:

    asdf list-all python

    2. You can now install a specific version of Python (for example, 3.11.4) by running:

    asdf install python <version>

    3. To install multiple versions at once, you can chain commands:

    asdf install python 3.10.15 && asdf install python 3.9.9

    Step 7: Set Global or Local Python Version

    To set a global version of Python that will be used system-wide, run:

    asdf global python 3.13.1

    If you want to set a specific version for a project directory, navigate to that directory and run:

    cd your_project_directory
    asdf local python 3.13.1

    Step 8: Verify Installation

    To confirm that the installation was successful, check the installed version of Python:

    python --version

    Installing Python Using Conda and Miniconda on Linux

    Miniconda is a lightweight version of Anaconda that includes only Conda and its dependencies, allowing you to install Python and manage packages effectively. Here’s a step-by-step guide to installing Python using Miniconda on a Linux system.

    Step 1: Download Miniconda Installer

    • Open your terminal.
    • Download the Miniconda installer for Linux. You can use wget or curl. For example:
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

    Step 2: Verify the Installer (Optional)

    It's a good practice to verify the integrity of the installer. You can find the hash values on the Miniconda website. Use the following command to check:

    chmod +x Miniconda3-latest-Linux-x86_64.sh

    Compare the output with the hash provided on the website.

    Step 3: Run the Installer

    Run the installer and Follow the on-screen prompts to complete the installation.

    ./Miniconda3-latest-Linux-x86_64.sh

    Follow the prompts in the terminal:

    • Press Enter to review the license agreement.
    • Type yes to accept the terms.
    • Choose an installation location (the default is usually fine).
    • Opt to initialize Miniconda by allowing it to modify your shell configuration file.

    Step 4: Initialize Conda

    After installation, you may need to initialize Conda for your shell. If you accepted this during installation, it should be done automatically. If not, you can run:

    conda init
    • Modifies your shell configuration file to activate the Conda environment automatically.
    • Ensures Conda commands like conda activate and conda deactivate work without additional configuration.

    Then, restart your terminal or run source ~/.bashrc (or source ~/.zshrc if you're using Zsh).

    Step 5: Install Python

    Create a new environment with a specific version of Python (for example, Python 3.13)

    conda create -n myenv python=<version>

    Activate the environment

    conda activate myenv

    Step 6: Verify Python Installation

    To check that Python is installed correctly within your environment, run:

    python --version

    Method 3: Manual Installation Methods for Python on Linux

    Installing Python on Linux can be done through various manual methods, primarily by using a package manager or building from source. Below are the detailed steps for each method.

    Building Python from Source Code

    If you need a specific version of Python or want to customize the installation, you can build it from source. This method gives you full control over the Python installation and allows customization during the build process:

    Step 1: Install Required Development Packages

    Before building Python, ensure you have the necessary development tools and libraries installed.

    sudo apt install build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libffi-dev zlib1g-dev

    Step 2: Download the Latest Version of Python

    Visit the official Python website and download the latest source code tarball. Alternatively, use wget to download it directly:

    wget https://www.python.org/ftp/python/X.Y.Z/Python-X.Y.Z.tgz 

    Replace <version> with the Python version you want (e.g., 3.13.1). This downloads the source code as a .tgz archive.

    Step 3: Extract Tarball and Navigate to the Source Directory

    After downloading, extract the tarball:

    tar -xvf Python-<version>.tgz

    Step 4: Configure the Build Environment

    Navigate to the extracted directory and configure the build environment:

    cd Python-X.Y.Z
    ./configure --enable-optimizations 
    • The --enable-optimizations flag can improve performance.
    • This unpacks the source code into a directory for building and installation.

    Step 5: Compile and Install

    Compile the source code and install it:

    This uses all available cores for faster compilation:

    make -j $(nproc) 

    Use altinstall to prevent overwriting any existing python binary:

    sudo make altinstall

    Step 5: Verify the Installation

    After installation, verify that Python is installed correctly by checking its version:

    python3 --version

    Replace 3.10 with the installed version to confirm it’s correctly installed.

    Installing Python Using the Official Installer on Linux

    To install Python on Linux using the official installer, you typically download the source code from the Python website and compile it. Here’s a step-by-step guide to perform this installation.

    Step 1: Download the Latest Python Version

    Go to python.org to find the latest version of Python.

    You can download the latest version as a tarball. For example, use wget in your terminal:

    wget https://www.python.org/ftp/python/<version>/Python-<version>.sh

    Replace <version> with the version you want to install.

    Step 2: Install Required Development Packages

    Before compiling Python, ensure that you have the necessary development tools installed.

    For Ubuntu/Debian, run:

    sudo apt update
    sudo apt install build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libffi-dev zlib1g-dev

    For Fedora, you can install development tools with:

    sudo dnf groupinstall "Development Tools"

    Step 3: Extract the Downloaded Tarball

    Once the download is complete, extract the tarball:

    tar -xf Python-X.Y.Z.tgz
    cd Python-X.Y.Z

    Step 4: Configure the Build Environment

    Run the configuration script to prepare for building:

    ./configure --enable-optimizations

    The --enable-optimizations flag helps optimize the Python binary for better performance.

    Step 5: Compile and Install

    Compile the source code and install Python:

    This uses all available CPU cores for faster compilation.

    make -j $(nproc) 

    This prevents overwriting any existing python binary.

    sudo make altinstall

    Step 6: Verify Installation

    Check if Python has been installed correctly by running:

    python3 --version

    Installing Python Using Docker Containers on Linux

    Docker provides a convenient way to run applications in isolated environments, making it easy to manage dependencies and versions. Here’s how to install Python using Docker containers on a Linux system.

    Step 1: Install Docker

    If you haven't already installed Docker, you can do so by following these steps:

    Update your package index:

    sudo apt update

    Install Docker:

    For Ubuntu/Debian-based systems:

    sudo apt install -y docker.io

    For Fedora-based systems:

    sudo dnf install -y docker

    For Arch-based systems:

    sudo pacman -S docker

    Start and enable Docker:

    Start the Docker service and enable it to start automatically on boot:

    sudo systemctl start docker
    sudo systemctl enable docker

    Docker is a containerization tool that runs applications, including Python, in isolated containers.

    Step 2: Pull the Python Docker Image

    Docker provides official Python images that are lightweight and pre-configured for different versions. Copy the below command to pull the Python Docker image for the desired version:

    sudo docker pull python:<version>

    Replace <version> with the desired Python version (e.g., 3.10). This downloads the image containing Python.

    Step 3: Run Python in a Container

    Once the image is downloaded, you can start a container with Python. Follow the below command to Run Python Container:

    sudo docker run -it python:<version>
    • The -it option starts an interactive terminal.
    • The Python REPL (interactive shell) will launch within the container.

    This launches an interactive Python shell inside a container.

    Step 4: Run Python Scripts in a Container

    Now you can run a Python script stored on your host machine, use Docker’s volume mounting feature to share the file with the container.

    Installing Python on Linux Using Snap Packages

    Snap packages provide a convenient way to install and manage software on Linux systems in a containerized format. Here’s a step-by-step guide to installing Python using Snap packages.

    Step 1: Install Snap

    If Snap is not already installed on your system, you can install it using the following commands based on your Linux distribution:

    For Ubuntu/Debian:

    sudo apt update
    sudo apt install -y snapd

    For Fedora:

    sudo dnf install snapd

    For Arch Linux:

    sudo pacman -S snapd

    Note: After installation, ensure that the Snap service is enabled:

    sudo systemctl enable --now snapd.socket

    Step 2: Install Python Using Snap

    You can find available Python versions in the Snap store by running:

    snap find python

    To install the latest version of Python, you can use:

    sudo snap install python3

    Replace python3 with the specific version you want (e.g., python3.13)

    Step 3: Verify the Installation

    Once the installation is complete, verify that Python has been installed correctly by checking its version:

    python3 --version

    This confirms the Snap package installed Python successfully.

    Method 4: Installing Python on Linux Using Cloud-Based Solutions

    Cloud-based environments provide a flexible way to install and run Python without the need for local setup. Here’s how to install Python using popular cloud platforms like AWS Cloud9 and Google Cloud Compute Engine.

    Installing Python Using Cloud Provider Tools on Linux

    Most cloud providers, like AWS, Google Cloud, and Azure, offer pre-configured environments with Python.

    Step 1: Choose a Cloud Provider

    Select a cloud provider that supports Python. Common options:

    • AWS (Amazon Web Services): Use EC2 instances or AWS Lambda.
    • Google Cloud Platform (GCP): Use Compute Engine or App Engine.
    • Microsoft Azure: Use Azure Virtual Machines or Functions.

    These providers offer ready-to-use instances with Python pre-installed or easily configurable.

    Step 2: Launch a Virtual Machine (VM)

    VMs allow you to run Python as if on a physical machine, giving you control over installations.

    1. Log in to the cloud provider’s console.
    2. Create a new VM instance.
    3. Choose an OS and ensure Python is included in the configuration or installable.

    Step 3: Install or Use Pre-installed Python

    Some cloud VMs come with Python pre-installed. You can verify it using python3 --version. But If Python isn’t pre-installed the follow the below commands:

    SSH into the VM:

    ssh user@<VM-IP>

    Install Python using package managers or version managers:

    sudo apt install python3

    How to Install Python Using Deadsnakes PPA (Ubuntu Only)

    Deadsnakes PPA is used to install newer Python versions which are not available in the default repositories. The deadsnakes PPA is a trusted repository that provides the latest Python versions for Linux-based distributions.

    Step 1: Install a tool to add PPAs

    sudo apt install software-properties-common

    Step 2: Add the Deadsnakes Repository

    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt update

    Step 3: Install a specific Python version (e.g., 3.13)

    sudo apt install python3.13

    How to Verify Python Installation on Linux

    After installation, Confirm that Python and pip were installed correctly. These commands ensure Python and pip are installed and accessible from the terminal.

    Check Python Version

    python3 --version

    Check pip Version

    pip3 --version

    Conclusion

    Installing Python on Linux is a straightforward process when using package managers or trusted repositories like deadsnakes PPA. By following this guide, you’ll have Python and its tools ready for development. Isolating projects with virtual environments and managing Python versions with pyenv ensures a clean and flexible setup for all your projects.

    Create Quiz

    A

    Abhinav96
    Improve

    A

    Abhinav96
    Improve
    Article Tags :
    • Python
    • python-basics
    • linux

    Explore

      Python Fundamentals

      Python Introduction

      2 min read

      Input and Output in Python

      4 min read

      Python Variables

      4 min read

      Python Operators

      4 min read

      Python Keywords

      2 min read

      Python Data Types

      8 min read

      Conditional Statements in Python

      3 min read

      Loops in Python - For, While and Nested Loops

      5 min read

      Python Functions

      5 min read

      Recursion in Python

      4 min read

      Python Lambda Functions

      5 min read

      Python Data Structures

      Python String

      5 min read

      Python Lists

      4 min read

      Python Tuples

      4 min read

      Python Dictionary

      3 min read

      Python Sets

      6 min read

      Python Arrays

      7 min read

      List Comprehension in Python

      4 min read

      Advanced Python

      Python OOP Concepts

      11 min read

      Python Exception Handling

      5 min read

      File Handling in Python

      4 min read

      Python Database Tutorial

      4 min read

      Python MongoDB Tutorial

      3 min read

      Python MySQL

      9 min read

      Python Packages

      10 min read

      Python Modules

      3 min read

      Python DSA Libraries

      15 min read

      List of Python GUI Library and Packages

      3 min read

      Data Science with Python

      NumPy Tutorial - Python Library

      3 min read

      Pandas Tutorial

      4 min read

      Matplotlib Tutorial

      5 min read

      Python Seaborn Tutorial

      3 min read

      StatsModel Library - Tutorial

      3 min read

      Learning Model Building in Scikit-learn

      6 min read

      TensorFlow Tutorial

      2 min read

      PyTorch Tutorial

      6 min read

      Web Development with Python

      Flask Tutorial

      8 min read

      Django Tutorial | Learn Django Framework

      7 min read

      Django ORM - Inserting, Updating & Deleting Data

      4 min read

      Templating With Jinja2 in Flask

      6 min read

      Django Templates

      5 min read

      Build a REST API using Flask - Python

      3 min read

      Building a Simple API with Django REST Framework

      3 min read

      Python Practice

      Python Quiz

      1 min read

      Python Coding Practice

      1 min read

      Python Interview Questions and Answers

      15+ min read
    top_of_element && top_of_screen < bottom_of_element) || (bottom_of_screen > articleRecommendedTop && top_of_screen < articleRecommendedBottom) || (top_of_screen > articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Job-A-Thon
  • Blogs
  • Nation Skill Up
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • Interview Preparation
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • Trending Technologies
  • Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.
See More

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences