If you're a developer or someone who frequently interacts with GitHub repositories, the GitHub CLI (Command Line Interface) is an essential tool that streamlines your workflow. It allows you to manage issues, pull requests, and repositories directly from your terminal, saving you time and effort. Installing GitHub CLI is straightforward and can be accomplished on various operating systems. In this guide, we'll walk you through the step-by-step process to install GitHub CLI on Windows, macOS, and Linux, ensuring you're set up to enhance your GitHub experience.
Prerequisites for Installing GitHub CLI
Before proceeding with the installation, ensure your system meets the following prerequisites:
- Access to a terminal or command prompt (PowerShell, Terminal, Bash, etc.)
- Administrator or sudo privileges on your computer
- Internet connection to download the installer or package
Installing GitHub CLI on Windows
Windows users have multiple options to install GitHub CLI, including using the Windows Installer, package managers like Chocolatey, or Windows Package Manager (winget). Below are the most common methods:
Method 1: Using the Windows Installer
- Visit the official GitHub CLI releases page: https://github.com/cli/cli/releases.
- Download the latest
gh_x.x.x_windows_amd64.msiinstaller file. - Run the installer and follow the on-screen instructions to complete the installation.
- Once installed, open Command Prompt or PowerShell and verify the installation by typing:
You should see the version number of GitHub CLI displayed.gh --version
Method 2: Using Chocolatey Package Manager
- Open an elevated Command Prompt or PowerShell window.
- If you haven't installed Chocolatey, follow the instructions at https://chocolatey.org/install.
- Install GitHub CLI by running:
choco install gh - After installation, confirm by typing:
gh --version
Method 3: Using Windows Package Manager (winget)
- Open Command Prompt or PowerShell.
- Run the following command:
winget install --id=GitHub.cli --source=winget - Verify installation:
gh --version
Installing GitHub CLI on macOS
Mac users can install GitHub CLI via Homebrew, MacPorts, or by downloading the package directly.
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 ready, install GitHub CLI with:
brew install gh - Verify the installation:
gh --version
Method 2: Downloading the Binary
- Visit the GitHub CLI releases page: https://github.com/cli/cli/releases.
- Download the latest
gh_x.x.x_macOS.tar.gzfile. - Extract the archive and move the
ghbinary to a directory in your PATH, such as/usr/local/bin. - Make the binary executable:
chmod +x /usr/local/bin/gh - Check the version:
gh --version
Installing GitHub CLI on Linux
Linux distributions support GitHub CLI through various package managers. The installation process varies based on your distro.
Method 1: Using apt (Debian/Ubuntu)
- Open your terminal.
- Update your package list:
sudo apt update - 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 echo "deb [arch=$(dpkg --print-architecture)] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null - Update package list again:
sudo apt update - Install GitHub CLI:
sudo apt install gh - Verify the installation:
gh --version
Method 2: Using yum/dnf (Fedora/CentOS)
- Open Terminal.
- Add the repository and install:
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo sudo dnf install gh - Check the version:
gh --version
Method 3: Using Snap (Universal Linux Method)
- Ensure snapd is installed and enabled.
- Install GitHub CLI:
sudo snap install gh --classic - Verify:
gh --version
Post-Installation: Authenticating with GitHub CLI
After installing GitHub CLI, you'll need to authenticate to access your repositories and perform various tasks. To authenticate, simply run:
gh auth login
This command guides you through the authentication process, allowing you to log in via your browser or provide a personal access token. Once authenticated, you can start managing issues, pull requests, and repositories directly from your terminal.
Using GitHub CLI Effectively
Now that you have installed and authenticated GitHub CLI, here are some common commands to get you started:
-
Clone a repository:
gh repo clone owner/repo -
Create a new issue:
gh issue create -
List open pull requests:
gh pr list -
Checkout a pull request:
gh pr checkout 123 -
Create a new repository:
gh repo create -
View repository details:
gh repo view
Conclusion
Installing the GitHub CLI is a valuable step toward streamlining your development workflow. Whether you're using Windows, macOS, or Linux, the process is simple and can be tailored to your preferred method, whether via native installers, package managers, or direct downloads. Once installed and authenticated, the CLI empowers you to manage your GitHub repositories more efficiently, perform common tasks faster, and stay productive from your terminal. Embrace the power of GitHub CLI today and take your project management to the next level!
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.