Terminal Installation – How to Install tar.gz File Directly from URL

installterminal

Suppose we have a web url to a .tar.gz file.

We could download it, unzip/tar it, and install it.

Is there an elegant way of doing all of the above from terminal, preferably with a one-liner?

Example tar.gz file: https://cran.r-project.org/src/base/R-3/R-3.5.0.tar.gz

Note: I don't mind using a program to do this, but much prefer everything done from the terminal, mostly for efficiency, fewer steps, and being able to give reproducible instructions to others

Best Answer

This will work better as a script that accepts a parameter.

tar_from_url() {
    URL="$1"
    curl -O "$URL"
    tar -xvf "${URL##*/}"
    rm "${URL##*/}"
}

So basically use curl to download, then use tar to extract, finally get rid of downloaded file.

The installation part needs still to be done manually though. The name of the directory it extracts to is unknown and different depending on the actual tar file, as is the method required for installation itself.