gh: command not found / gh is not recognized errors [Fixed]

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
8 min

banner

# Table of Contents

  1. Installing the GitHub CLI (gh) on Windows
  2. Installing the GitHub CLI (gh) on macOS
  3. Installing the GitHub CLI (gh) on Linux
  4. Installing the GitHub CLI (gh) using Anaconda

# gh: command not found / gh is not recognized errors [Fixed]

The "gh: command not found" error occurs when you try to issue the gh command in a shell on macOS or Linux without having the GitHub CLI installed.

The "'gh' is not recognized as an internal or external command, operable program or batch file" command occurs when you try to issue the gh command on Windows, without having the GitHub CLI installed.

To resolve the issue, you have to install the GitHub CLI for your operating system.

This article contains step-by-step instructions on how to install the GitHub CLI on all operating systems (Windows, macOS and Linux).

Make sure to click on the subheading that covers your operating system.

  1. Installing the GitHub CLI (gh) on Windows
  2. Installing the GitHub CLI (gh) on macOS
  3. Installing the GitHub CLI (gh) on Linux
  4. Installing the GitHub CLI (gh) using Anaconda

# Installing the GitHub CLI (gh) using Chocolatey on Windows

If you have Chocolatey installed:

  1. Click on the Search bar and type PowerShell.

  2. Right-click on the PowerShell application and click "Run as administrator".

run powershell as administrator

  1. Run the following command to install gh.
PowerShell
# install gh choco install gh -y # Or upgrade gh choco upgrade gh

install gh using chocolatey

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You can also try using the refreshenv command in PowersShell/CMD.

PowerShell
refreshenv

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list
If you don't have Chocolatey installed, you have to install it first.

To install Chocolatey:

  1. Open PowerShell as an administrator.

run powershell as administrator

  1. Run the following command.
PowerShell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

windows install chocolatey

  1. Wait for the command to complete.
  2. Type choco to make sure Chocolatey is installed.

windows verify chocolatey installed

Now that you have Chocolatey installed, run the following command to install curl.

PowerShell
choco install gh -y

Note that your shell should still be run using elevated permissions.

chocolatey install curl

Now you should be able to use the gh command.

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You can also try using the refreshenv command in PowersShell/CMD.

PowerShell
refreshenv

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI (gh) using Scoop on Windows

If you use scoop, you can install the GitHub CLI by running the following command.

shell
# to install gh scoop install gh # or to update gh scoop update gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You can also try using the refreshenv command in PowersShell/CMD.

PowerShell
refreshenv

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI (gh) using WinGet on Windows

If you'd rather use WinGet to install gh on Windows, run the following command instead.

shell
# To install the GitHub CLI winget install --id GitHub.cli # Or to update the GitHub CLI winget upgrade --id GitHub.cli

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You can also try using the refreshenv command in PowersShell/CMD.

PowerShell
refreshenv

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Table of Contents

  1. Installing the GitHub CLI (gh) on macOS
  2. Installing the GitHub CLI (gh) on Linux
  3. Installing the GitHub CLI (gh) using Anaconda

# Installing the GitHub CLI (gh) using Brew on macOS

You can use Homebrew to install the GitHub CLI (gh) on macOS.

Open your terminal and run the following command.

shell
# To install the GitHub CLI brew install gh # Or to update the GitHub CLI brew upgrade gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI (gh) using MacPorts on macOS

If you'd rather use MacPorts to install the GitHub CLI, run the following command instead.

shell
# To install the GitHub CLI sudo port install gh # To upgrade the GitHub CLI sudo port selfupdate && sudo port upgrade gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI (gh) using Spack on macOS

You can also use Spack to install the GitHub CLI on macOS.

Open your terminal and run the following command.

shell
# To install the GitHub CLI spack install gh # Or to upgrade the GitHub CLI spack uninstall gh && spack install gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Install the GitHub CLI (gh) using Anaconda

You can also use Anaconda to install the GitHub CLI.

Open your terminal and run the following command.

shell
conda install gh --channel conda-forge

If you need to upgrade the GitHub CLI, run the following command instead.

shell
conda update gh --channel conda-forge

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Install the GitHub CLI (gh) on Debian, Ubuntu, Raspberry Pi OS

If you need to install the GitHub CLI on Debian, Ubuntu or Raspberry Pi OS, open your terminal and issue the following commands.

shell
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) 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 gh -y

If you need to upgrade the GitHub CLI, run the following command.

shell
sudo apt update sudo apt install gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI (gh) on Fedora, CentOS and Red Hat

If you need to install the GitHub CLI on Fedora, CentOS or Red Hat, open your terminal and run the following commands.

shell
sudo dnf install 'dnf-command(config-manager)' sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo sudo dnf install gh

The commands above install the GitHub CLI from the package's repository.

You can also install the package using the community repository.

shell
sudo dnf install gh

If you need to upgrade the GitHub CLI on Fedora, CentOS or Red Hat, run the following command.

shell
sudo dnf update gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI on Amazon Linux 2 (yum)

If you need to install the GitHub CLI on Amazon Linux 2 using yum, issue the following commands.

shell
type -p yum-config-manager >/dev/null || sudo yum install yum-utils sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo sudo yum install gh

GitHub recently changed its GPG signing key.

If you get a GPG signing key error:

  1. Disable the repository with the following command.
shell
sudo yum-config-manager --disable gh-cli
  1. Add the repository again with the following command
shell
sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
  1. Upgrade the GitHub CLI package.
shell
sudo yum update gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Installing the GitHub CLI on openSUSE/SUSE Linux with zypper

If you need to install the GitHub CLI on openSUSE, run the following commands.

shell
sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo sudo zypper ref sudo zypper install gh

If you need to upgrade the GitHub CLI, run the following commands instead.

shell
sudo zypper ref sudo zypper update gh

NOTE: the installation command changes your PATH environment variable.

You have to close and reopen your shell to be able to use the gh command.

You first have to run the gh auth login command to authenticate.

PowerShell
gh auth login

Once you issue the gh auth login command, the CLI will prompt you how you want to authenticate.

Follow the steps and run the gh issue list command to verify everything works.

shell
gh issue list

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.