Resolving "gh: command not found" or "gh is not recognized" Errors
Introduction
Running into a "gh: command not found" or "gh is not recognized" error message can be frustrating. This typically occurs when the GitHub CLI (gh) is not installed on your system or the path to the executable is not correctly set.
In this Byte, we'll walk you through the process of installing GitHub CLI on Windows and macOS using different package managers.
There are a lot of ways to do this between the various operating systems and package managers. I'd recomment you look at the Table of Contents on the right to find your OS and preferred installer to more easily find what you need.
For each of the install methods below, once the installation completes, you can verify that it installed correctly by running:
$ gh --version
gh version 1.14.0 (2021-04-19)
Install GitHub CLI (gh) on Windows via Chocolatey
Chocolatey is a package manager for Windows. If you haven't installed it yet, you can do so by following the instructions on the official Chocolatey website. Once you have Chocolatey installed, open your command prompt as an administrator and run the following command:
$ choco install gh
Install GitHub CLI (gh) on Windows via Scoop
Scoop is another package manager for Windows. If you don't have Scoop installed, you can follow the instructions on the official Scoop website to install it. Once Scoop is installed, open your command prompt and run the following command:
$ scoop install gh
Install GitHub CLI (gh) on Windows via WinGet
WinGet is a package manager that comes with Windows 10. You can install GitHub CLI using WinGet by opening your command prompt as an administrator and running the following command:
$ winget install gh
Note: If you are using an older version of Windows, WinGet may not be available. In that case, consider using Chocolatey or Scoop.
Install GitHub CLI (gh) on macOS via Brew
Homebrew, often referred to as Brew, is a popular package manager for macOS. If you haven't installed it yet, you can do so by following the instructions on the official Homebrew website. Once you have Brew installed, open your terminal and run the following command:
$ brew install gh
Install GitHub CLI (gh) on macOS via MacPorts
To install the GitHub CLI (gh) on macOS using MacPorts, you first need to ensure that you have MacPorts installed on your system. If not, you can install it from the MacPorts website. Once MacPorts is installed, you can install the GitHub CLI by running the following command in your terminal:
$ sudo port install gh
This command will download and install the GitHub CLI on your system.
Install GitHub CLI (gh) on macOS via Spack
Spack is another package manager for macOS that you can use to install the GitHub CLI. To install Spack, follow the instructions on the official Spack website. After installing Spack, you can install the GitHub CLI by running:
$ spack install gh
Install GitHub CLI (gh) using Anaconda
Anaconda is a popular Python distribution that includes a package manager called conda. You can use conda to install the GitHub CLI. First, ensure that you have Anaconda installed on your system. If not, download and install it from the Anaconda website. Once Anaconda is installed, open the Anaconda Prompt and run:
$ conda install -c conda-forge gh
This command will install the GitHub CLI.
Install GitHub CLI (gh) on Debian, Ubuntu, Raspberry Pi OS
To install the GitHub CLI on a Debian-based system like Debian, Ubuntu, or Raspberry Pi OS, you can use the apt package manager. First, update your package lists by running:
$ sudo apt update
Then, install the GitHub CLI by running:
$ sudo apt install gh
Install GitHub CLI (gh) on Fedora, CentOS and Red Hat
On Fedora, CentOS, and Red Hat, you can use the dnf package manager to install the GitHub CLI. First, update your system by running:
$ sudo dnf update
Then, install the GitHub CLI by running:
$ sudo dnf install gh
Note: The exact command to install the GitHub CLI may vary slightly depending on your specific Linux distribution and version.
Install GitHub CLI (gh) on Amazon Linux 2 (yum)
To install GitHub CLI on Amazon Linux 2, we will use yum
, which is the default package manager for this distribution. First, let's update the system packages using the following command:
$ sudo yum update -y
Next, we need to download the GitHub CLI rpm
package. You can always find the latest version on the GitHub CLI releases page. As of writing this guide, the latest version is 1.14.0. Replace the version in the command below if a newer version is available:
$ wget https://github.com/cli/cli/releases/download/v1.14.0/gh_1.14.0_linux_amd64.rpm
Then, install the downloaded package using yum
:
$ sudo yum localinstall gh_1.14.0_linux_amd64.rpm
Install GitHub CLI (gh) on openSUSE/SUSE Linux with zypper
For openSUSE/SUSE Linux, we will use zypper
to install GitHub CLI. Start by updating your system packages:
$ sudo zypper refresh
Next, add the GitHub CLI repository to your system:
$ sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo
Now, you can install gh
using zypper
:
$ sudo zypper install gh
Note: Be sure to replace 1.14.0
with the latest version available at the time of your installation.
Conclusion
In this guide, we've covered how to install the GitHub CLI on quite a few operating systems / distros and package managers, like Windows, macOS, Debian and brew
, port
, choco
, yum
, etc. With these steps, you should be able to fix the "gh: command not found" or "gh is not recognized" errors. Remember to always verify your installations by checking the version of your installed packages.