CentOs:无法使用 curl 提取下载的 tar

CentOs: Cannot extract downloaded tar using curl

我正在尝试使用 curl 下载 node

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

现在,在我的 Mac 上这行得通。然而,在 CentOs 中,这不起作用:

$> 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)

我不明白这里到底发生了什么。

如果我拆分命令并执行

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

有效。基于此,也许 curl 解压缩了我已经尝试过的文件

$> 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)

不 :( 如有任何帮助,我们将不胜感激?

当您在 tar 中使用选项“-z”时,应用程序正在等待 .gz(gunzip)格式。

您应该使用选项 "J":

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