Installing GitHub CLI Without Root

On shared machines, clusters, or restricted servers, I often do not have root access. That does not mean I need to give up useful tools like GitHub CLI.

The simple approach is to install gh under ~/.local:

mkdir -p ~/.local/bin ~/.local/opt

Then download the official Linux tarball from the GitHub CLI releases page, extract it into ~/.local/opt/gh, and symlink the binary:

ln -sf ~/.local/opt/gh/bin/gh ~/.local/bin/gh

Finally, make sure ~/.local/bin is in PATH:

export PATH = " $HOME /.local/bin: $PATH "

The following code snippet can be used to automate the installation of gh without root privileges:

mkdir -p ~/.local/bin ~/.local/opt cd /tmp

ARCH = " $( uname -m ) " case " $ARCH " in x86_64 ) GH_ARCH = "amd64";; aarch64 | arm64 ) GH_ARCH = "arm64";; armv7l ) GH_ARCH = "armv6";; • ) echo " Unsupported architecture: $ARCH "; exit 1;; esac

VERSION = " $( curl -fsSL api.github.com/repos/cli/cli/releases/latest \ | grep '"tag_name":' \ | sed -E 's/."v([^"]+)"./\1/' ) "

curl -fL -o " gh_ ${ VERSION } linux ${ GH_ARCH }.tar.gz " \ "github.com/cli/cli/releases/download/v ${ VERSION } /gh_ ${ VERSION } linux ${ GH_ARCH }.tar.gz "

tar -xzf " gh_ ${ VERSION } linux ${ GH_ARCH }.tar.gz "

rm -rf " $HOME /.local/opt/gh " mv " gh_ ${ VERSION } linux ${ GH_ARCH } " " $HOME /.local/opt/gh "

ln -sf " $HOME /.local/opt/gh/bin/gh " " $HOME /.local/bin/gh "

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc export PATH = " $HOME /.local/bin: $PATH "

gh --version

This keeps the install local, clean, removable, and independent of system packages. It is also a good pattern for many CLI tools on machines where sudo is unavailable.

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论