Your Search Bar For Shrewd Tips

How To Install Gh Cli


How To Install Gh CLI

If you're a developer or someone who frequently interacts with GitHub, the GitHub CLI (gh) is an invaluable tool that streamlines your workflow. The GitHub CLI allows you to manage issues, pull requests, and repositories directly from your terminal, making your development process more efficient and integrated. Installing the gh CLI is straightforward, whether you're on Windows, macOS, or Linux. This guide will walk you through the step-by-step process to install the GitHub CLI on your system, ensuring you can start leveraging its powerful features quickly.

Prerequisites for Installing GitHub CLI

Before you begin the installation process, ensure your system meets the following prerequisites:

  • Access to a terminal or command prompt.
  • Administrative or root privileges on your machine.
  • An active internet connection to download the necessary files.
  • Compatible operating system: Windows, macOS, or Linux.

Additionally, it's recommended to have Git installed on your system, as the GitHub CLI often integrates seamlessly with Git workflows. You can verify if Git is installed by running git --version in your terminal. If not installed, follow the respective instructions for your OS to install Git before proceeding.

Installing GitHub CLI on Windows

Windows users have multiple options to install the GitHub CLI, including using the Windows Installer or package managers like Chocolatey or Scoop. Here’s how to install gh CLI on Windows:

Method 1: Using the Windows Installer

  • Visit the GitHub CLI releases page.
  • Download the latest gh_X.Y.Z_windows_amd64.msi installer file.
  • Run the downloaded MSI file and follow the on-screen prompts to complete the installation.
  • Once installed, open Command Prompt or PowerShell and verify the installation by typing:
gh --version
  • If installed correctly, the CLI version will display.
  • Method 2: Using Chocolatey

    • Open an elevated Command Prompt or PowerShell window.
    • Run the following command to install gh CLI via Chocolatey:
    choco install gh
  • After installation, verify by typing:
  • gh --version

    Method 3: Using Scoop

    scoop install gh
  • Verify the installation with:
  • gh --version

    Installing GitHub CLI on macOS

    Mac users can install the GitHub CLI using Homebrew, MacPorts, or by downloading the binary directly. The most common method is using Homebrew:

    Method 1: Using Homebrew

    • Open Terminal.
    • If you don’t have Homebrew installed, install it by running:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Once Homebrew is installed, update it:
  • brew update
  • Install the GitHub CLI with:
  • brew install gh
  • Verify the installation by typing:
  • gh --version

    Method 2: Using MacPorts

    • Install MacPorts if you haven't already, following instructions at MacPorts official site.
    • Open Terminal and run:
    sudo port install gh
  • Verify installation with:
  • gh --version

    Method 3: Downloading Binary

    • Navigate to the GitHub CLI releases page.
    • Download the latest gh_X.Y.Z_macOS.pkg installer.
    • Open the downloaded package and follow the installation prompts.
    • Confirm installation by running:
    gh --version

    Installing GitHub CLI on Linux

    Linux users have several options depending on their distribution, including apt for Debian/Ubuntu, dnf or yum for Fedora, and pacman for Arch Linux. Follow the steps corresponding to your Linux distribution.

    Debian/Ubuntu

    • Open your terminal.
    • First, install the necessary dependencies:
    sudo apt update
    sudo apt install -y curl
  • Add the GitHub CLI repository:
  • curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
    sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
  • Update your package list and install:
  • sudo apt update
    sudo apt install -y gh
  • Verify by running:
  • gh --version

    Fedora

    • Open terminal.
    • Run the following command:
    sudo dnf install 'https://github.com/cli/cli/releases/download/vX.Y.Z/gh_X.Y.Z_linux_amd64.rpm'
  • Check the installation:
  • gh --version

    Arch Linux

    • Open terminal.
    • Install via the AUR or using the community repository:
    sudo pacman -S github-cli
  • Verify installation:
  • gh --version

    Post-Installation: Authenticating GitHub CLI

    After installing the gh CLI, you need to authenticate to access your repositories and perform various tasks. Here's how to authenticate:

    • Open your terminal or command prompt.
    • Run the command:
    gh auth login
  • Follow the prompts to choose your preferred authentication method. You can authenticate via a web browser or by entering a personal access token.
  • If you choose web-based login, a browser window will open, prompting you to authorize the CLI.
  • Once authenticated, you can verify your login status with:
  • gh auth status

    Using GitHub CLI After Installation

    With the GitHub CLI installed and authenticated, you can start managing your GitHub repositories directly from your terminal. Here are some common commands to get you started:

    • Clone a repository: gh repo clone owner/repository
    • Create a new repository: gh repo create
    • View issues: gh issue list
    • Create an issue: gh issue create
    • Create a pull request: gh pr create
    • View pull requests: gh pr list

    Conclusion

    Installing the GitHub CLI (gh) enhances your development workflow by allowing you to manage repositories, issues, and pull requests seamlessly from your terminal. Whether you're using Windows, macOS, or Linux, the installation process is straightforward and well-supported with various package managers and direct downloads. Once installed, authenticating and exploring the rich set of commands will empower you to work more efficiently with your GitHub projects. Embrace the power of the GitHub CLI today and take your development experience to the next level.


    Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

    Shrewdnia

    Shrewdnia

    Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


    πŸ’‘ Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments πŸ‘‡

    Back to blog

    Leave a comment

    JOIN THE SHREWDNIA COMMUNITY FORUM

    What do you think?

    Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

    Join the Forum β†’