~dmi3 page

How to download latest release from Github

Sometimes you might want to download latest release of binary from Github repo using script. You can do this using API, but lets assume that on some enviroments you have only basic tools, and no jq to extract values from JSon.

  1. Git hub has built in redirect, i.e. https://github.com/user/repo/releases/latest which redirect to page dedicated to latest release
  2. We can get redirect url with curl, i.e. curl -Ls -o /dev/null -w "%{url_effective}" https://github.com/user/repo/releases/latest will get us https://github.com/user/repo/releases/tag/0.15.9
  3. Now we can extract version by using basename, i.e. basename https://github.com/user/repo/releases/tag/0.15.9 will return 0.15.9
  4. Using this version we can construct download url.

For example script that downloads and installs latest version of fzf

    export FZF_VERSION=$(curl -Ls -o /dev/null -w "%{url_effective}" https://github.com/junegunn/fzf-bin/releases/latest | xargs basename)
    curl -L https://github.com/junegunn/fzf-bin/releases/download/$FZF_VERSION/fzf-$FZF_VERSION-linux_amd64.tgz | tar -xz -C /tmp/
    sudo mv /tmp/fzf-$FZF_VERSION-linux_amd64 /usr/bin/fzf

If you have anything on your mind, drop me email @tilde.club. Lets talk!

Click for the [ Random page ]
Want to join the ring? Click here for info.