Skip Navigation

Scott Spence

GitHub CLI Installation Guide for WSL (Ubuntu)

3 min read

Real quick on this one! I need to document it though as this has been a persistent pain for me for a while! Getting the GitHub gh CLI to work in Windows Subsystem for Linux (WSL). Well, turns out it’s still an issue! But with some searching and Clauding I was able to get it working!

Anyway Tl;Dr go to here WSL auth

Install command

So, first up that scary looking install command from the official GitHub CLI docs:

(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) 
  && sudo mkdir -p -m 755 /etc/apt/keyrings 
  && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg 
  && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null 
  && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg 
  && sudo mkdir -p -m 755 /etc/apt/sources.list.d 
  && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/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

Like? Really?? I know most installers be in a “trust me bro” install script but compare that to the brew install gh for Homebrew users! Or how I installed in Arch yay github-cli feels a bit janky.

What each part does

I had Claude break down the commands and what they do here:

CommandPurpose
type -p wget >/dev/null \|\| (sudo apt update && sudo apt install wget -y)Checks if wget exists; installs it if missing
sudo mkdir -p -m 755 /etc/apt/keyringsCreates the keyrings directory with proper permissions (read/execute for all, write for owner)
out=$(mktemp)Creates a temporary file and stores its path in $out
wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpgDownloads GitHub’s GPG signing key to the temp file (-nv = not verbose)
cat $out \| sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/nullCopies the key to the keyrings directory (needs tee for sudo write permissions)
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpgMakes the key readable by group and others
sudo mkdir -p -m 755 /etc/apt/sources.list.dEnsures the apt sources directory exists
echo "deb [arch=... signed-by=...] https://cli.github.com/packages stable main"Constructs the apt source entry with your CPU architecture and the signing key path
\| sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/nullWrites the source entry to a new apt list file
sudo apt updateRefreshes package lists (now includes GitHub’s repo)
sudo apt install gh -yInstalls the gh package without prompting

The && chains mean each command only runs if the previous one succeeded.

Authenticate

That’s it! Then the fun begins with trying to auth in WSL.

gh auth login

Follow the prompts:

  1. Select GitHub.com
  2. Select HTTPS (or SSH if you prefer)
  3. Choose Login with a web browser

But don’t! Skip to the next section.

WSL auth

This is a known issue affecting WSL users. If you get this error:

failed to authenticate via web browser: Too many requests have been made in the same timeframe. (slow_down)

Fix: When prompted to press Enter to open the browser, don’t press it yet. Instead:

  1. Copy the one-time code shown
  2. Manually open https://github.com/login/device in your browser
  3. Paste the code
  4. Complete auth in browser
  5. Return to terminal

Success??! This is what worked for me and this is why I’m documenting here!

This workaround is documented in the issue comments and worked for me!

Verify installation

Check if all good by checking the version and the auth status.

gh --version
gh auth status

Done

I’m now able to use the GitHub CLI in my WSL with (so far) no issues!

There's a reactions leaderboard you can check out too.

Sign up for the newsletter

Want to keep up to date with what I'm working on?

Join other developers and sign up for the newsletter.

I care about the protection of your data. Read the Privacy Policy for more info.

Copyright © 2017 - 2026 - All rights reserved Scott Spence