How to download a Tarball from GitHub on Linux?


Github is an online source code repository and hosting service for open-source projects, which provides the ability to host, version control, review, fork, and submit changes to any project hosted there.

The following steps will help you download a tarball of your choice from github.com −

  • By using git clone

  • Download Git repository as a tar or zip file

You can use either the command line tool "Github" (which is installed by default) or the GUI client "SourceTree". However, if you don't have these tools, you can download the source code in tar format and extract its contents on the file systems.

Here, we’ll take a quick peek at some Linux commands to get the source code for the GitHub project from the command line.

In this tutorial, you will learn how to download and install the latest version of a tarball from GitHub. This is useful if you want to use an older version of a library that has been updated in the meantime or if you want to try out a new feature before it's released. You can also use this method to get access to the source code for a project without having to register at GitHub first.

Using wget Command

Apart from curl, which is a general purpose tool for executing HTTP requests, Linux also has a wget program which is a dedicated non interactive network download tool.

It supports HTTP and HTTPS protocols and so can also be used to download repository archives from Github.

wget https://github.com/tutorialspoint/linux-tutorials/tarball/master -O linux.tgz

If you run the following commands from the directory where the.tgz file is located, they will be downloaded to the same place where the commands were executed.

We can unpack the archive file inline −

wget https://github.com/tutorialspoint/linux-tutorials/tarball/master -O - | tar -xz

The -O option directs the contents of the archive to the standard output and serves as input for the tardar (the archiver) program.

You can use the –no-check-certificate option when running wget to avoid checking for an SSL/TLS certificate.

wget --no-check-certificate https://github.com/tutorialspoint/linux-tutorials/tarball/master -O - | tar -xz

Using curl Command

Since GitHub allows us to download archives over HTTP, we can use the `cURL` command to download this archive from GitHub.

curl -L https://github.com/tutorialspoint/linux-tutorials/tarball/master -o dummy.tgz

We used the -c option to tell curl to use cookies. Without this option, curl would not be able to access our GitHub account.

To get the.tar.gz file from the previous step, run the following command.

We can also unpack inline −

curl -L https://github.com/tutorialspoint/linux-tutorials/tarball/master | tar -xz

Curl can usually handshake an HTTPS connection with GitHub. However, when this handshake doesn't succeed, we can instead opt for the insecure option in curl.

curl -L -k https://github.com/tutorialspoint/linux-tutorials/tarball/master | tar -xz

Downloading From Private GitHub Repositories

We've covered some basic commands for using Git repositories, but if you're working with a private repository, you'll need to use GitHub Access Tokens instead.

curl -L -k -u token:x-oauth-basic https://github.com/tutorialspoint/linux-tutorials/tarball/master | tar -xz

Here, the token refers to an alphanumeric OAUTH token which we need to include in our GitHub profile.

Conclusion

Here, we've looked at two methods for downloading repositories from GitHub. We've used the curl and wget command line tools to do so.

We also saw various command line arguments to disable SSL validation and inline unpacking. Additionally, we used curl to download a public repository using OAuth credentials.

Updated on: 01-Dec-2022

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements