218

Using GitHub's Release feature, it is possible to provide a link to download a specific version of the published software. However, every time a release is made, the gh-page also needs to be updated.

Is there a way to get a link to a specific file of whatever the latest version of a software is?

e.g., this would be a static link:

https://github.com/USER/PROJECT/releases/download/v0.0.0/package.zip

What I'd like is something like:

https://github.com/USER/PROJECT/releases/download/latest/package.zip

NOTE: The difference between this question and GitHub latest release is that this question specifically asks for getting access to the file, not the GitHub latest release page

Community
  • 1
  • 1
Christian Rondeau
  • 4,143
  • 5
  • 28
  • 46
  • 4
    This is supported natively by Github now (with a slight difference in the URL format). See https://stackoverflow.com/questions/24987542/is-there-a-link-to-github-for-downloading-a-file-in-the-latest-release-of-a-repo/54836319#54836319 – wisbucky Sep 18 '19 at 20:54

21 Answers21

150

A few years late, but I just implemented a simple redirect to support https://github.com/USER/PROJECT/releases/latest/download/package.zip. That should redirected to the latest tagged package.zip release asset. Hope it's handy!

Joshua Peek
  • 1,540
  • 1
  • 7
  • 2
  • 18
    Documented on https://help.github.com/en/articles/linking-to-releases: _If you'd like to link directly to a download of your latest release asset you can link to /owner/name/releases/latest/download/asset-name.zip_ – Liam Apr 09 '19 at 07:30
  • 16
    It would be helpful if this feature worked with versioned asset names, however. – Liam Apr 09 '19 at 07:32
  • 15
    Note that the order is switched `.../releases/latest/download/...` vs `.../releases/download/v0.0.0/...`. You cannot simply replace `v0.0.0` with `latest` in place. – wisbucky Sep 18 '19 at 20:53
  • 7
    @Joshua Peek Maybe you could extend this to expand "LATEST" in the asset name to be the version string? That would make it useful for assets with version numbers in their name. – jwatt Dec 01 '19 at 16:36
  • 11
    What about downloading the latest source code? What is the name of the asset in that case? – skd Jul 21 '20 at 10:55
  • 2
    Currently **/releases/latest/download/package.zip** is no longer work. Result in not found. Example: https://github.com/FortAwesome/Font-Awesome/releases/latest/download/package.zip – vee Jan 18 '22 at 06:31
  • this does still work – stackers Feb 24 '22 at 18:35
  • Doesn't work for me as well: https://github.com/rust-lang/mdBook/releases/latest/download/package.zip. – Marcus May 13 '22 at 21:49
  • 4
    I'm confused by this answer. Where did you implement this? Do you work at Github and just like that implemented the feature. Or is it an API available at an URL that's somehow not linked to? – Cornelius Roemer May 23 '22 at 19:51
  • 3
    The people in the comments who are saying this isn't working are likely confused by the fact this answer is only giving an example of downloading a file called "package.zip" from the release. If your asset is called "foo.zip", you need to change it to that. If your asset is called "foo-1.2.3.zip" where 1.2.3 is the version of the release, you'll have to use a different method. – gsgx Sep 22 '22 at 20:27
  • @gsgx what he is mentioning is a very common issue about that, sadly it looks like GitHub has no solution to that just yet – Mb175 Nov 18 '22 at 18:28
  • As github cannot know which file you want when you say 'latest' it's impossible to avoid having the file name in the link. For example : https://github.com/rust-lang/mdBook/releases/latest/download/mdbook-v0.4.28-x86_64-pc-windows-msvc.zip . But then this doesn't really help because when you call latest you don't know the version and maybe don't care so it's like a half working system. – Keytrap Apr 25 '23 at 13:35
  • @gsgx Whilst these users both linked to package.zip files that didn't exist (causing the download to fail), I think that they are (accidentally) correct that this method no longer works. At least, it doesn't appear to work for me. – DyedPurple Aug 04 '23 at 15:46
72

Linux solution to get latest release asset download link (works only if release has one asset only)

curl -s https://api.github.com/repos/boxbilling/boxbilling/releases/latest | grep browser_download_url | cut -d '"' -f 4
Putna
  • 1,171
  • 1
  • 11
  • 7
  • 9
    One additional grep in the pipeline will find the file for your distribution and architecture. For the [atom](https://github.com/atom/atom) text editor on 64-bit Ubuntu: `curl -s https://api.github.com/repos/atom/atom/releases | grep browser_download_url | grep '64[.]deb' | head -n 1 | cut -d '"' -f 4` – hobs May 31 '15 at 18:26
  • 4
    There is no browser_download_url any more. You can use tarball_url now. `curl -s https://api.github.com/repos/git-ftp/git-ftp/releases | grep tarball_url | head -n 1 | cut -d '"' -f 4` – maikel Apr 23 '16 at 07:13
  • 4
    @maikel grepping for browser_download_url still works for me. – Léo Lam Apr 29 '16 at 12:35
  • @léo-lam You are right. Just if you don't have assets, you can use the tarball_url to get the source code. – maikel May 01 '16 at 00:21
  • You can only load the latest release to avoid `| head -n 1` https://api.github.com/repos/boxbilling/boxbilling/releases/latest – ya.teck Jun 27 '17 at 04:25
  • 2
    @ya.teck `/latest` only list stable release, not draft or prerelease: https://developer.github.com/v3/repos/releases/#get-the-latest-release – Julien Ma May 07 '18 at 17:11
34

You can do an ajax request to get latest release download URL using the GitHub Releases API. It also shows when it was released and the download count:

function GetLatestReleaseInfo() {
    $.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function(release) {
        UpdateDownloadButton(release, ".exe", $(".setup"));
        UpdateDownloadButton(release, "portable.zip", $(".portable"));
    });
}

function UpdateDownloadButton(release, assetExtension, element) {
    let asset = release.assets.find(asset => asset.name.endsWith(assetExtension));
    let releaseInfo = "Version: " + release.tag_name.substring(1) +
        "\nFile size: " + (asset.size / 1024 / 1024).toFixed(2) + " MB" +
        "\nRelease date: " + new Date(asset.updated_at).toLocaleDateString("en-CA") +
        "\nDownload count: " + asset.download_count.toLocaleString();

    element.attr("href", asset.browser_download_url);
    element.attr("title", releaseInfo);
}

GetLatestReleaseInfo();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="setup" href="https://github.com/ShareX/ShareX/releases/latest">Setup</a>
<a class="portable" href="https://github.com/ShareX/ShareX/releases/latest">Portable</a>

When the request completes, the URL of buttons will change automatically to a direct download URL.

Jaex
  • 4,204
  • 2
  • 34
  • 56
  • Cool. Do you know why this might not be working? `curl -s https://api.github.com/repos/DataTables/DataTables/releases/latest` – Volte Oct 27 '15 at 21:30
  • Because you don't have any release. Check: https://api.github.com/repos/DataTables/DataTables/releases – Jaex Oct 29 '15 at 07:07
  • Funky... https://github.com/DataTables/DataTables/releases shows a bunch of releases. There must be some ambiguity there. – Volte Oct 29 '15 at 15:49
  • No, these are only tags. There are no releases. – MrD Jan 18 '17 at 17:19
  • Why is this blank? https://api.github.com/repos/jquery/jquery/releases There should be plenty of releases. – Hamid Sarfraz May 24 '17 at 20:09
  • https://api.github.com/repos/jquery/jquery/releases/latest returns 404. This returns empty string: https://api.github.com/repos/webix-hub/tracker/releases while both of these projects have releases. Why is the API behavior inconsistent? Any documentation on this? – Hamid Sarfraz May 24 '17 at 20:19
  • 2
    https://github.com/jquery/jquery/releases they don't have any releases. It is just version tags. – Jaex May 25 '17 at 00:05
  • This is useless for the places where it would be needed. As in: Shell scripts. – Evi1M4chine Mar 06 '18 at 12:56
  • @Evi1M4chine question was asking it for web pages not shell scripts. – Jaex Mar 06 '18 at 16:44
  • I think it makes more sense to do this server-sided. Also, unless someone is already using jquery, prescribing it for this _one_ thing is overkill. Ajax with vanilla JS isn't hard. Unless you want extremely wide browser support. In that case, do it on the server side. Unless there's some reason to doing it client side, but if there is that should be mentioned in the answer. – Mr. Nobody Aug 08 '18 at 04:29
  • @CoryRs I'm using GitHub pages for static web site hosting therefore couldn't do it server side. – Jaex Aug 08 '18 at 08:27
  • If what you are trying to do is automate getting the download url for the latest release available on github, then @IanB's [answer](https://stackoverflow.com/a/29360657/1365918) below is the way to go. Using jq to parse the output from Github's API and getting the download url needed. You can then use wget to get the actual file. Tried and tested in scripts and works perfectly for me. – kapad Oct 09 '18 at 20:26
19

From the command line using curl and jq, retrieves the first file of the latest release:

curl -s https://api.github.com/repos/porjo/staticserve/releases/latest | \
  jq --raw-output '.assets[0] | .browser_download_url'
IanB
  • 2,642
  • 22
  • 25
  • 3
    `jq --raw-output` is a cleaner way to drop the quotes. If you only want the latest it's cheaper to fetch `.../releases/latest` and drop the `.[0] | `. But fetching all releases allows queries like `jq '.[] | .assets[] | .browser_download_url | select(endswith(".deb"))'`... – Beni Cherniavsky-Paskin Jun 07 '15 at 13:30
  • Thanks Beni, I expanded on this for grabbing the latest docker-compose, ```curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | jq --arg PLATFORM_ARCH "$(echo `uname -s`-`uname -m`)" -r '.assets[] | select(.name | endswith($PLATFORM_ARCH)).browser_download_url' | xargs sudo curl -L -o /usr/local/bin/docker-compose --url ```. The endswith was the magic and using the arch allows me to ignore the whatever.sha256 files that are typically present without doing `|head -n 1`. – dragon788 Jul 18 '18 at 16:01
11

Another Linux solution using curl and wget to download a single binary file from the latest release page

curl -s -L https://github.com/bosun-monitor/bosun/releases/latest | egrep -o '/bosun-monitor/bosun/releases/download/[0-9]*/scollector-linux-armv6' | wget --base=http://github.com/ -i - -O scollector

Explanation:

curl -s -L is to silently download the latest release HTML (after following redirect)

egrep -o '...' uses regex to find the file you want

wget --base=http://github.com/ -i - converts the relative path from the pipeline to absolute URL

and -O scollector sets the desired file name.

may be able to add -N to only download if the file is newer but S3 was giving a 403 Forbidden error.

Greg Bray
  • 14,929
  • 12
  • 80
  • 104
  • 3
    My goal is to make a link on a website that always points to the latest version. A linux command will not allow that. – Christian Rondeau Jan 13 '15 at 15:23
  • 1
    This is what I was looking for but you have to make sure you have the correct escape characters for wildcards and dots when using grep. – T. Thomas Aug 21 '16 at 20:52
  • @TdotThomas thanks, that's the hint I needed for semver release numbers to escape the periods `\.` e.g. 2.2.0 needed `/download/[0-9\.]*/` – Jeff Puckett Nov 26 '16 at 04:15
  • No, it doesn't. No escape char. But i **would** presume an optional `v` as prefix, like a tag `v0.11.0`. Just input `curl -s -L https://github.com/bosun-monitor/bosun/releases/latest | egrep -o '/bosun-monitor/bosun/releases/download/[v]?[0-9.]*/scollector-linux-armv6' | wget --base=http://github.com/ -i - -O scollector` in your CLI and it works perfectly. Thank you, Greg!! – MS Berends Apr 12 '17 at 11:56
10

Github now supports static links for downloading individual files from the latest release: https://help.github.com/en/articles/linking-to-releases

https://github.com/USER/PROJECT/releases/latest/download/package.zip
Kaloyan Raev
  • 167
  • 2
  • 6
  • 1
    The same answer was already posted 6 months prior: https://stackoverflow.com/questions/24987542/is-there-a-link-to-github-for-downloading-a-file-in-the-latest-release-of-a-repo/54836319#54836319 – wisbucky Sep 18 '19 at 20:48
  • Thanks for bringing this to my attention @wisbucky, I dismissed it then since it sounded like a custom implementation from a developer, not someone from StackOverflow! – Christian Rondeau Sep 19 '19 at 12:51
  • this doesn't seem to work even thought it's in the docs - also it would be inconsistent to see /releases/latest/download/ when download links are of the style /releases/download/0.7.1/... (the version is at the end) – George Birbilis Nov 13 '22 at 15:01
9

This can be done in a single one-liner like so:

$ curl -s https://api.github.com/repos/slmingol/gorelease_ex/releases/latest \
    | grep -wo "https.*Linux.*gz" | wget -qi -

Here we're:

  • Pulling the API side of GitHub to get information about the release artifacts with the tag latest.
  • Parse that output looking for an artifact that matches the pattern https.*Linux.*gz.
  • Pass the URL to the command wget -qi - so that it'll get downloaded

To further reveal what's going on here's a broader grep of the API endpoint:

$ curl -s https://api.github.com/repos/slmingol/gorelease_ex/releases/latest | grep -wo "https.*" | grep gz
https://github.com/slmingol/gorelease_ex/releases/download/0.0.78/gorelease_ex_0.0.78_Darwin_x86_64.tar.gz"
https://github.com/slmingol/gorelease_ex/releases/download/0.0.78/gorelease_ex_0.0.78_Linux_x86_64.tar.gz"

Above you can see the URLs that matched.

Further tip

You can also parameterize the grep argument so that it'll "dynamically" determine what platform it was run on and substitute in the appropriate string based on that.

$ curl -s https://api.github.com/repos/slmingol/gorelease_ex/releases/latest \
    | grep -wo "https.*$(uname).*gz" | wget -qi -

Here $(uname) will return either Darwin, Linux, etc.

slm
  • 15,396
  • 12
  • 109
  • 124
8

Just use one of the urls below to download the latest release: (took urls from boxbilling project for example): https://api.github.com/repos/boxbilling/boxbilling/releases

Download the latest release as zip: https://api.github.com/repos/boxbilling/boxbilling/zipball

Download the latest release as tarball: https://api.github.com/repos/boxbilling/boxbilling/tarball

Click on one of the urls to download the latest release instantly. As i wrote this lines it's currently: boxbilling-boxbilling-4.20-30-g452ad1c[.zip/.tar.gz]

UPDATE: Found an other url in my logfiles (ref. to example above) https://codeload.github.com/boxbilling/boxbilling/legacy.tar.gz/master

Lahmizzar
  • 487
  • 6
  • 6
8

As noted previously, jq is useful for this and other REST APIs.

tl;dr - more details below

Assuming you want the macOS release:

URL=$( curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
   | jq -r '.assets[] | select(.name=="atom-mac.zip") | .browser_download_url' )
curl -LO "$URL"

Solution for atom releases

Note each repo can have different ways of providing the desired artifact, so I will demonstrate for a well-behaved one like atom.

Get the names of the assets published

curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
    | jq -r '.assets[] | .name'

atom-1.15.0-delta.nupkg
atom-1.15.0-full.nupkg
atom-amd64.deb
...

Get the download URL for the desired asset

Below atom-mac is my desired asset via jq's select(.name=="atom-mac.zip")

curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
    | jq -r '.assets[] | select(.name=="atom-mac.zip") | .browser_download_url'

https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip

Download the artifact

curl -LO "https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip"

jq Playground

jq syntax can be difficult. Here's a playground for experimenting with the jq above: https://jqplay.org/s/h6_LfoEHLZ

Security

You should take measures to ensure the validity of the downloaded artifact via sha256sum and gpg, if at all possible.

Mike D
  • 5,984
  • 4
  • 31
  • 31
8

A solution using (an inner) wget to get the HTML content, filter it for the zip file (with egrep) and then download the zip file (with the outer wget).

wget https://github.com/$(wget https://github.com/<USER>/<PROJECT>/releases/latest -O - | egrep '/.*/.*/.*zip' -o)
Rolf
  • 1,129
  • 11
  • 27
8

Not possible according to GitHub support as of 2018-05-23

Contacted support@github.com on 2018-05-23 with message:

Can you just confirm that there is no way besides messing with API currently?

and they replied:

Thanks for reaching out. We recommend using the API to fetch the latest release because that approach is stable, documented, and not subject to change any time soon:

https://developer.github.com/v3/repos/releases/#get-the-latest-release

I will also keep tracking this at: https://github.com/isaacs/github/issues/658

Python solution without any dependencies

Robust and portable:

#!/usr/bin/env python3

import json
import urllib.request

_json = json.loads(urllib.request.urlopen(urllib.request.Request(
    'https://api.github.com/repos/cirosantilli/linux-kernel-module-cheat/releases/latest',
     headers={'Accept': 'application/vnd.github.v3+json'},
)).read())
asset = _json['assets'][0]
urllib.request.urlretrieve(asset['browser_download_url'], asset['name'])

See also:

Also consider pre-releases

/latest does not see pre-releases, but it is easy to do since /releases shows the latest one first:

#!/usr/bin/env python3

import json
import urllib.request

_json = json.loads(urllib.request.urlopen(urllib.request.Request(
    'https://api.github.com/repos/cirosantilli/linux-kernel-module-cheat/releases',
     headers={'Accept': 'application/vnd.github.v3+json'},
)).read())
asset = _json[0]['assets'][0]
urllib.request.urlretrieve(asset['browser_download_url'], asset['name'])
Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • GitHub support didn't bother to check that their documentation is wrong? Plus don't they get it that end users need a consistent url and not scripts? – George Birbilis Nov 13 '22 at 14:59
6

The Linking to releases help page does mention a "Latest Release" button, but that doesn't get you a download link.

https://github.com/reactiveui/ReactiveUI/releases/latest

For that, you need to get the latest tag first (as mentioned in "GitHub URL for latest release of the download file?"):

latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)

curl -L https://github.com/reactiveui/ReactiveUI/releases/download/$latestTag/ReactiveUI-$latestTag.zip
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    This still requires to push a new version of the `gh-pages` branch everytime a new release is made; the objective is to have a static link I can use to just "refer to the latest version". Right now my best option is to just refer to the releases page. – Christian Rondeau Jul 28 '14 at 19:11
  • @ChristianRondeau I agree. I didn't see anywhere in the API a way to reference the "latest" release archive full url directly. – VonC Jul 28 '14 at 19:45
  • Still, thanks for the tip; if no better answers are provided, I'll probably end up doing a script to update gh-pages using your script. – Christian Rondeau Jul 28 '14 at 20:10
3

I want to download the releases from the README.md file in the repository description. There, I cannot execute JavaScript.

I can add links like these to the README file or github pages for all of my repositories:

  • https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/<FILE>
    Downloads the latest release file from the repository.
  • https://niccokunzmann.github.io/download_latest/<FILE>
    This works because the JavaScript referrer is set and the repository to download is determined through document.referrer. Thus, the link will also work for forks.

You can find the source code here, fork or just use my repo.

User
  • 14,131
  • 2
  • 40
  • 59
  • 1
    That's a pretty clever idea :) it won't work when sharing links or using curl or the likes, but this idea can be done in the project's github pages. – Christian Rondeau Apr 29 '17 at 11:22
  • 1
    SInce this is possible as a JavaScript website, one could also write a service that does a redirect. http://download-service.com/organization/repository/artifact – User Apr 29 '17 at 20:03
  • Seems to work fine, any tips on how one can host it at their own xx.github.io site? (so that they're sure it stays alive and pointing to the files they expect it to) – George Birbilis Nov 13 '22 at 14:57
  • You should be able to fork it and then enable github pages in the settings of the fork. – User Nov 15 '22 at 23:14
3

in PHP - redirect to the latest release download. Simply put on your webspace

<?php

/**
 * Download latest release from github release articats
 * License: Public Domain
 */

define('REPO', 'imi-digital/iRobo');

$opts = [
    'http' => [
        'method' => 'GET',
        'header' => [
            'User-Agent: PHP'
        ]
    ]
];

$context = stream_context_create($opts);

$releases = file_get_contents('https://api.github.com/repos/' . REPO . '/releases', false, $context);
$releases = json_decode($releases);

$url = $releases[0]->assets[0]->browser_download_url;

header('Location: ' . $url);
Alex
  • 32,506
  • 16
  • 106
  • 171
3

If you want to use just curl you can try with -w '%{url_effective}' that prints the URL after a redirect chain (followed by curl if you invoke it with -L). So, for example

curl -sLo /dev/null -w '%{url_effective}' https://github.com/github-tools/github/releases/latest

outputs https://github.com/github-tools/github/releases/tag/v3.1.0.

3

The benefit of this solution is that you don't have to specify any release or tag number- it will just grab the LATEST.

TESTING:

I conducted my testing using the following Github user & repo:

"f1linux" = Github User
"pi-ap" = Repo

The arbitrary directory name the repo is saved to is set in:

--one-top-level="pi-ap"

DIRECT:

Using Firefox's "Web Developer" tools (3 bars in upper right corner), in the "Network" section I found https://api.github.com was redirecting to https://codeload.github.com, so by piping the curl to tar I was able to grab the latest versioned repo and save it to a predictable name so it could be operated on:

curl https://codeload.github.com/f1linux/pi-ap/legacy.tar.gz/master | tar xzvf - --one-top-level="pi-ap" --strip-components 1

INDIRECT:

After I achieved fully-automated downloads of the latest versioned release using a DIRECT URL, I turned my attention to achieving the same with Github's redirection:

curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1

Preferred Method:

However, please note as per Von's comment below that INDIRECT is the preferred method

Further Validation:

To ensure my results were reproducible to other versioned Github repos, the same tests were successfully executed for Digital Ocean's doctl api toolkit (which is what started the whole exercise actually!):

Both DIRECT and INDIRECT work using the same form as above, just changing the username & repo:

DIRECT:

curl https://codeload.github.com/digitalocean/doctl/legacy.tar.gz/master | tar xzvf - --one-top-level="doctl" --strip-components 1 

INDIRECT:

curl -L https://api.github.com/repos/digitalocean/doctl/tarball | tar xzvf - --one-top-level="doctl" --strip-components 1
F1Linux
  • 3,580
  • 3
  • 25
  • 24
  • I ran into grief with the redirection initially and as noted in the answer Firefox's "Web Developer" tools got me going on the right track. Couldn't stop there though, had to get it working with the redirection. Thanks for the upvote- most obliged! – F1Linux Mar 30 '20 at 12:08
  • 1
    @VonC Just added your feedback to the answer. I was totally unaware of this. Thanks for pointing it out! – F1Linux Mar 30 '20 at 12:25
3

This is for Linux.

I saw the above accepted answer

A few years late, but I just implemented a simple redirect to support https://github.com/USER/PROJECT/releases/latest/download/package.zip. That should redirected to the latest tagged package.zip release asset. Hope it's handy!

by Joshua Peek but a comment noted it didn't support versioned file names.

After searching for a bit, I made up a one line call that works for versioned file names. It uses curl to get the latest file version and then makes use of the redirect support that was added to download the latest versioned file.

wget $'https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest/download/<FILE NAME START>-'$(curl -s https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest | grep -o -P '(?<=releases/tag/).*(?=\">)')$'<FILE NAME END>'

So it targets a file that's named like <REPO NAME>-linux64_arm-<VERSION NUMBER>.tar.gz that's on the webpage https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest after it redirects. It does this by looking for the <VERSION NUMBER> between releases/tag/ and the "> in the text that's returned from the curl call. So to be really explicit, <FILE NAME START> is the <REPO NAME>-linux64_arm- and <FILE NAME END> is the .tar.gz in the above example. Get the START and END bits by looking at what the https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest uses as its file naming scheme.

I made this up by mimicking how grep and curl were used by others and just learned all of this now, so let me know if it's doing something real naughty that I wouldn't even fathom! Also I am saying <UMBRELLA PROJECT> but a user name should be able to go there just fine as well. Shout out to https://stackoverflow.com/a/13245961/2403531 for the grep call, https://unix.stackexchange.com/a/10264 for the $string$concatenation.

user2403531
  • 688
  • 6
  • 15
2

In case you want to use in alpine, follow these steps:

 apk add curl ca-certificates wget
wget -q $(curl -s https://api.github.com/repos/<USER>/<REPOSITORY>/releases/latest | grep browser_download_url | grep "$ARCH" | cut -d '"' -f 4)

The -q flag in wget is quiet mode. If you want to see the output then use without -q.

smottt
  • 3,272
  • 11
  • 37
  • 44
1

In case that the repo is using just tags instead of release -- cf. jQuery -- the solutions which based on one URL does not work.

Instead, you have to query all tags, sort them and construct the download URL. I implemented such a solution for the language Go and the jQuery repo: Link to Github.

Perhaps, this helps someone.

SommerEngineering
  • 1,412
  • 1
  • 20
  • 26
0

simple command which works and download the latest package available in the github release

curl -ks https://api.github.com/repos/<reponame>/releases/latest | grep "browser_download_url.*linux-amd64.tar.gz" | cut -d : -f 2,3 | tr -d \" | xargs wget --no-check-certificate
  • reponame - replace it with github repo with available packages in release
  • Type of package .tar.gz can be replaced as per need. Ex - .zip etc
Ashwani Singh
  • 876
  • 11
  • 10
0

There is a dirty trick that uses internal github.com webserver latest redirect rule. But this rule doesn't exist on raw.githubusercontent.com host.

For example we can install the latest available nvm using the following code:

curl -s -w '%header{location}' "https://github.com/nvm-sh/nvm/releases/latest/download/install.sh" | \
  sed -e 's/\/\/github.com/\/\/raw.githubusercontent.com/' -e 's/\/releases\/download//' | \
  xargs curl -o- | bash
puchu
  • 3,294
  • 6
  • 38
  • 62