How do I download a tarball from GitHub using cURL?

LinuxCurlGithubWget

Linux Problem Overview


I am trying to download a tarball from GitHub using cURL, but it does not seem to be redirecting:

$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being <a href="https://nodeload.github.com/pinard/Pymacs/tarball/v0.24-beta2">redirected</a>.</body></html>

Note: wget works for me:

$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2

However I want to use cURL because ultimately I want to untar it inline with something like:

$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx

I found that the URL after redirecting turned out to be https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar.gz, but I would like cURL to be smart enough to figure this out.

Linux Solutions


Solution 1 - Linux

Use the -L option to follow redirects:

curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx

Solution 2 - Linux

The modernized way of doing this is:

curl -sL https://github.com/user-or-org/repo/archive/sha1-or-ref.tar.gz | tar xz

Replace user-or-org, repo, and sha1-or-ref accordingly.

If you want a zip file instead of a tarball, specify .zip instead of .tar.gz suffix.

You can also retrieve the archive of a private repo, by specifying -u token:x-oauth-basic option to curl. Replace token with a personal access token.

Solution 3 - Linux

You can also use wget to »untar it inline«. Simply specify stdout as the output file (-O -):

wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2 -O - | tar xz

Solution 4 - Linux

All the other solutions require specifying a release/version number which obviously breaks automation.

This solution- currently tested and known to work with Github API v3- however can be used programmatically to grab the LATEST release without specifying any tag or release number and un-TARs the binary to an arbitrary name you specify in switch --one-top-level="pi-ap". Just swap-out user f1linux and repo pi-ap in below example with your own details and Bob's your uncle:

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

Solution 5 - Linux

with a specific dir:

cd your_dir && curl -L https://download.calibre-ebook.com/3.19.0/calibre-3.19.0-x86_64.txz | tar zx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsaltycraneView Question on Stackoverflow
Solution 1 - LinuxsaltycraneView Answer on Stackoverflow
Solution 2 - LinuxPavel RepinView Answer on Stackoverflow
Solution 3 - LinuxknittlView Answer on Stackoverflow
Solution 4 - LinuxF1LinuxView Answer on Stackoverflow
Solution 5 - LinuxzhengquanView Answer on Stackoverflow