Install GitHub CLI on Raspberry Pi

Install GitHub CLI on Raspberry Pi

GitHub CLI is a tool that enables to login to GitHub account via command line and manage pull requests, issues, releases, gists, and other GitHub actions.

This tutorial demonstrates how to install GitHub CLI on Raspberry Pi.

Install GitHub CLI

Use SSH to connect to Raspberry Pi. Retrieve the latest version tag of GitHub CLI release and assign it to variable.

GITHUB_CLI_VERSION=$(curl -s "https://api.github.com/repos/cli/cli/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Navigate to your home directory and download the .deb package from releases page of the GitHub CLI repository.

cd ~
curl -Lo gh.deb "https://github.com/cli/cli/releases/latest/download/gh_${GITHUB_CLI_VERSION}_linux_armv6.deb"

Run the following command to install GitHub CLI:

sudo dpkg -i gh.deb

Once installation is completed, GitHub CLI will be available with gh command. We can check version:

gh --version

We can remove .deb package because it is no longer needed.

rm -rf gh.deb

Testing GitHub CLI

In order to use the GitHub CLI we need to create token. Sign in to GitHub and go to settings page. Generate a new personal access token or use existing token.

Create a new text file to store token.

echo 'YOUR GITHUB API TOKEN' > github_token.txt

Execute the following command to login to GitHub account:

gh auth login --with-token < github_token.txt

We can view authentication status as follows:

gh auth status

Now we can perform various GitHub actions. For example, the following command retrieves a list of repositories owned by Google:

gh repo list google

If you want to log out of a GitHub, use this command:

gh auth logout

Uninstall GitHub CLI

If GitHub CLI is no longer needed, you can remove it with command:

sudo dpkg -r gh

You can also remove GitHub CLI configuration:

rm -rf ~/.config/gh

The 2 Comments Found

  1. Avatar
    Seamus Reply

    Excellent! As of ver 2.8 (perhaps earlier), the gh auth login procedure has several options. I feel it might be best for some users to simply enter gh auth login, and let gh walk you through the options. In my case, I don't wish to use a token; I use SSH & my pub key for authentication. And that's my only point, really - all the options are available this way.

    gh isn't in the "official" rpi repo - that's unfortunate, but the commands above give you all you need to learn when an upgrade is needed... or is that built into gh?

    • Avatar
      lindevs Reply

      Hi
      Regarding GitHub CLI upgrade. At this moment gh command doesn't provide any option that allows to upgrade CLI itself to the latest version. I recommend to remove the GitHub CLI and install it by using the latest package that can be downloaded from repository. All steps mentioned in the tutorial.

Leave a Comment

Cancel reply

Your email address will not be published.