Download github release with curl

CurlGithub

Curl Problem Overview


On this URL I'm able to download a .tar.gz which contains an official release. (I know it's also available on an API endpoint but this contains the test package too.

Now I'm wondering why this isn't working:

$ curl -O https://github.com/yarnpkg/yarn/releases/download/v0.23.4/yarn-v0.23.4.tar.gz

I get some .tar.gz which is 4KB instead of 3.6MB. It isn't showing an error. What am I missing? I want to use this URL and not the API if that's possible.

Curl Solutions


Solution 1 - Curl

If you do the following it will download correctly:

wget https://github.com/yarnpkg/yarn/releases/download/v0.23.4/yarn-v0.23.4.tar.gz

If you want to use curl you have to use the redirect -L option to follow redirect link and direct the output in a file like this:

curl -L https://github.com/yarnpkg/yarn/releases/download/v0.23.4/ya‌​rn-v0.23.4.tar.gz > yarn.tar.gz

Solution 2 - Curl

2021 Update Download from GitHub Using wget

Will also expand and delete the archive. Just edit the REPLACE_ values and then copy/paste

tgz

GH_USER=REPLACE_WITH_USER \
GH_REPO=REPLACE_WITH_REPO \
GH_BRANCH=REPLACE_WITH_BRANCH \
wget https://github.com/${GH_USER}/${GH_REPO}/archive/refs/tags/${GH_BRANCH}.tar.gz \
-O "${GH_REPO}-${GH_BRANCH}.tar.gz" && \
tar -xzvf ./"${GH_REPO}-${GH_BRANCH}.tar.gz" && \
rm ./"${GH_REPO}-${GH_BRANCH}.tar.gz"

zip

GH_USER=REPLACE_WITH_USER \
GH_REPO=REPLACE_WITH_REPO \
GH_BRANCH=REPLACE_WITH_BRANCH \
wget https://github.com/${GH_USER}/${GH_REPO}/archive/refs/tags/${GH_BRANCH}.zip \
-O "${GH_REPO}-${GH_BRANCH}.zip" && \ 
unzip ./"${GH_REPO}-${GH_BRANCH}.zip" && \
rm ./"${GH_REPO}-${GH_BRANCH}.zip"

Solution 3 - Curl

I hope this helps someone -> make sure your repository is public.

Then as explained in the other answers this should work:

curl -LO 'https://github.com/<user>/<repo>/archive/refs/tags/<1.0.0>.tar.gz'

When private, a token is required to access the release files, and you'll get NOT FOUND as a response. That was my issue.

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
QuestionDenCowboyView Question on Stackoverflow
Solution 1 - Curla.walkerView Answer on Stackoverflow
Solution 2 - CurlAndrewDView Answer on Stackoverflow
Solution 3 - CurlEvandro PomattiView Answer on Stackoverflow