GitHub CLI Installation on Ubuntu
I recently installed Ubuntu 26.04.1 on one of my laptops and wanted to add the GitHub CLI. I followed the official installation instructions and ran sudo apt install gh in the terminal.
But, of course there is a but; otherwise I wouldn’t be writing this post. The version installed was nowhere near the latest version from GitHub. I ran gh --version and got this:
gh version 2.46.0 (2026-06-18 Ubuntu 2.46.0-4ubuntu0.26.04.1~esm1)
https://github.com/cli/cli/releases/tag/v2.46.0I went through the instructions again, purged the package, and reinstalled it. The same result.
Note how the output refers to 2.46.0-4ubuntu0.26.04.1~esm1. gh is not being installed from the GitHub repository, but from the Ubuntu repository.
To confirm this, run apt-cache policy gh and you will see something like this:
1gh:
2 Installed: (none)
3 Candidate: 2.46.0-4ubuntu0.26.04.1~esm1
4 Version table:
5 2.101.0 500
6 500 https://cli.github.com/packages stable/main amd64 Packages
7 2.46.0-4ubuntu0.26.04.1~esm1 510
8 510 https://esm.ubuntu.com/apps/ubuntu resolute-apps-security/main amd64 Packages
9 2.46.0-4 500
10 500 http://us.archive.ubuntu.com/ubuntu resolute/universe amd64 PackagesLines 5 and 6: Even though I have added the GitHub repository, it is at a lower priority (500) than the Ubuntu repository (510).
Lines 7 and 8: The Ubuntu repository is the one that is being used to install gh.
I need to make the GitHub repository a higher priority. To do this, add a file called /etc/apt/preferences.d/github-cli with the following:
Package: gh
Pin: origin cli.github.com
Pin-Priority: 700Now run apt-cache policy gh again, and you should see -
1gh:
2 Installed: (none)
3 Candidate: 2.101.0
4 Version table:
5 2.101.0 700
6 500 https://cli.github.com/packages stable/main amd64 Packages
7 2.46.0-4ubuntu0.26.04.1~esm1 510
8 510 https://esm.ubuntu.com/apps/ubuntu resolute-apps-security/main amd64 Packages
9 2.46.0-4 500
10 500 http://us.archive.ubuntu.com/ubuntu resolute/universe amd64 PackagesNow, the GitHub repository has a higher priority, and when you try to install gh, it will be installed from the GitHub repository.
Run sudo apt install gh.