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.msiinstaller 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
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
gh --version
Method 3: Using Scoop
- Open PowerShell and ensure Scoop is installed. If not, install Scoop following Scoopβs official instructions.
- Run the command:
scoop install gh
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)"
brew update
brew install gh
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
gh --version
Method 3: Downloading Binary
- Navigate to the GitHub CLI releases page.
- Download the latest
gh_X.Y.Z_macOS.pkginstaller. - 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
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
sudo apt update
sudo apt install -y gh
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'
gh --version
Arch Linux
- Open terminal.
- Install via the AUR or using the community repository:
sudo pacman -S github-cli
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
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.