How to install Github Copilot Cli on lxplus

Tutorial on installing Github Copilot CLI on lxplus machines.

UPDATE: I have updated the tutorial to adjust for changing cli command and add section about how to upgrade gh 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.

LATEST_GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep "tag_name" | awk -F '"' '{print $4}')
wget 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.

tar xvfz gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz
rm -f gh_${LATEST_GH_VERSION#v}_linux_amd64.tar.gz
cd 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.

mv 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:

gh --version

Step 5: Installing GitHub Copilot CLI Extension

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

gh 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:

gh copilot

For more information, run:

gh 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.

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

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:

gh extension upgrade github/gh-copilot

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

function update_copilot_extension {
    gh extension upgrade github/gh-copilot
}

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

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

alias gh-update="update_gh_cli"
alias 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