Step 1: Update System Packages
Before installing GitHub CLI, ensure your system packages are up-to-date.
sudo apt-get update
sudo apt-get upgrade
Step 2: Install GitHub CLI
There are multiple ways to install GitHub CLI on Linux. We will use the package manager method here.
For Debian/Ubuntu-based distributions:
Install GitHub CLI using the apt package manager.
type -p curl >/dev/null || 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
For Fedora-based distributions:
Install GitHub CLI using the dnf package manager.
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
For CentOS/RHEL-based distributions:
Install GitHub CLI using the yum package manager.
sudo yum install yum-utils
sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo yum install gh
Step 3: Verify Installation
Check if GitHub CLI has been installed correctly by verifying its version.
gh --version
Step 4: Authenticate GitHub CLI
Authenticate GitHub CLI with your GitHub account to start using it.
gh auth login
Follow the prompts to authenticate. You can choose to authenticate via a web browser or by pasting an authentication token.
Step 5: Basic Usage of GitHub CLI
Now that you have GitHub CLI installed and authenticated, you can start using it for various GitHub operations. Here are a few basic commands:
Clone a repository:
gh repo clone owner/repo
Create a new repository:
gh repo create my-repo
List your repositories:
gh repo list
Create a new issue:
gh issue create
View pull requests:
gh pr list
Conclusion
Congratulations! You have successfully installed and configured GitHub CLI on your Linux system. With GitHub CLI, you can efficiently manage your repositories and perform various GitHub operations directly from the command line, streamlining your development workflow.