Mohamed Elashri

How to install Github Copilot Cli on lxplus

Info
I have updated the tutorial to adjust for changes in CLI commands and added a section about how to upgrade GitHub CLI and GitHub Copilot CLI.

In a previous blog post, I explained how to install GitHub Copilot on lxplus machines. In this post, I will explain how to install and handle updates for GitHub Copilot CLI on lxplus machines. GitHub Copilot CLI is a command-line tool that allows you to ask coding-related questions directly in your terminal. This is useful for quick assistance without switching to other interfaces.

The installation is similar to the GitHub CLI case, where we don’t have root permissions and need to manually install the binaries in our home directory. This tutorial also covers how to handle updates easily.

Prerequisites

Setup

Step 1: Downloading GitHub CLI

Begin by downloading the latest GitHub CLI (gh) binary. You can always check the GitHub CLI releases page for the most recent version. Here, we use version 2.46.0, but make sure to replace it with the latest available version when you follow these steps.

1LATEST_GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep "tag_name" | awk -F '"' '{print $4}')
2wget https://github.com/cli/cli/releases/download/$LATEST_GH_VERSION/gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz

This script dynamically fetches the latest release version of GitHub CLI. If you prefer, you can still manually visit the releases page and download the version you want.

Step 2: Extracting the Archive

Once the download completes, extract the archive and remove the tar.gz file.

1tar xvfz gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz
2rm -f gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz
3cd gh_${LATEST_GH_VERSION#v}_linux_amd64/

Step 3: Installing GitHub CLI

Move the gh binary to a directory in your path, such as $HOME/local/bin.

1mv bin/gh $HOME/local/bin

Ensure that $HOME/local/bin is in your PATH by adding export PATH="$HOME/local/bin:$PATH" to your .bashrc or .zshrc file if needed.

Step 4: Verifying the Installation

To verify that gh is correctly installed, run:

1gh --version

Step 5: Installing GitHub Copilot CLI Extension

With gh installed, you can now install the GitHub Copilot CLI extension:

1gh extension install github/gh-copilot

This installs the GitHub Copilot CLI extension, which allows you to use Copilot in your terminal. You can now run:

1gh copilot

For more information, run:

1gh copilot --help

That’s it! You have successfully installed GitHub Copilot CLI on your lxplus machine. You can now use Copilot in your terminal to get code suggestions and completions.

Handling Updates for GitHub CLI and Copilot CLI

To keep GitHub CLI and the Copilot extension up to date, follow these steps:

Step 1: Automating GitHub CLI Updates

You can add an alias or script to check for updates and automatically download the latest version of GitHub CLI.

 1function update_gh_cli {
 2    LATEST_GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep "tag_name" | awk -F '"' '{print $4}')
 3    INSTALLED_GH_VERSION=$(gh --version | head -n 1 | awk '{print $3}')
 4
 5    if [ "$LATEST_GH_VERSION" != "v$INSTALLED_GH_VERSION" ]; then
 6        echo "Updating GitHub CLI to version $LATEST_GH_VERSION"
 7        wget https://github.com/cli/cli/releases/download/$LATEST_GH_VERSION/gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz
 8        tar xvfz gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz
 9        mv gh_${LATEST_GH_VERSION#v}_linux_amd64/bin/gh $HOME/local/bin
10        rm -rf gh_${LATEST_GH_VERSION#v}_linux_amd64*
11    else
12        echo "GitHub CLI is up to date"
13    fi
14}

This script checks the installed version against the latest version available on GitHub and updates the binary if needed.

Step 2: Automating GitHub Copilot CLI Extension Updates

For updating the GitHub Copilot CLI extension, you can use the following command to ensure that the extension is up to date:

1gh extension upgrade github/gh-copilot

You can also add this to a function for easier use:

1function update_copilot_extension {
2    gh extension upgrade github/gh-copilot
3}

Step 3: Adding Update Commands to .bashrc (Optional)

To make it easier to manage updates, you can add aliases to your .bashrc or .zshrc:

1alias gh-update="update_gh_cli"
2alias copilot-update="update_copilot_extension"

Now, you can simply run gh-update or copilot-update to keep both tools up to date.

#Github #Copilot #Cli #Lxplus