Search code examples
curlcentosgziptarls

CentOs: Cannot extract downloaded tar using curl


I'm trying to download node using curl:

$>  curl https://nodejs.org/dist/latest/node-v6.6.0.tar.xz | tar xz -C /opt

Now, on my Mac this works. However, in CentOs, this doesn't work:

$> curl https://nodejs.org/dist/latest/node-v6.6.0.tar.xz | tar xz -C /opt
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
  0 14.8M    0   941    0     0   1214      0  3:33:54 --:--:--  3:33:54  1214
gzip: stdin: not in gzip format
tar: Child died with signal 13
tar: Error is not recoverable: exiting now
0 14.8M    0 42083    0     0  51628      0  0:05:01 --:--:--  0:05:01 51635
curl: (23) Failed writing body (246 != 1369)

I don't understand what exactly is going one here.

If I split the command and do

$> curl https://nodejs.org/dist/latest/node-v6.6.0.tar.xz > node.tgz
$> tar -xvf node.tgz // NOTE that I omitted the `z`

it works. Based on this, maybe curl unzipped the file already I tried

$> curl https://nodejs.org/dist/latest/node-v6.6.0.tar.xz | tar x -C /opt
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
0 14.8M    0   941    0     0   1005      0  4:18:23 --:--:--  4:18:23  1004tar: Archive is compressed. Use -J option
tar: Error is not recoverable: exiting now
0 14.8M    0 17325    0     0  18258      0  0:14:13 --:--:--  0:14:13 18256
curl: (23) Failed writing body (428 != 1369)

Nope :( Any help would be appreciated?


Solution

  • When you use the option "-z" in tar application is waiting .gz (gunzip) format.

    You should use the option "J":

    curl https://nodejs.org/dist/latest/node-v6.6.0.tar.xz | tar xJ -C /tmp