Extract a tar.xz file on CentOS and RedHat
This guide will show you how to extract a
tar.xz file on CentOS or RedHat, and probably other flavors of Linux as well. Traditionally compressed archive files are distributed on Linux systems as
tar.gz files which use
gzip for compression. Extracting them is as simple as passing
tar -xvf filename.tar.gz
If you try the same thing using a tar.xz file, you’ll find that it doesn’t work.
tar -xzf filename.tar.xz gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error exit delayed from previous errors
On newer versions of tar, you can simply replace the
z with a
J to use the correct (de)compression library, but if you have version 1.15.1 or earlier, you’ll find that this doesn’t work either. Note that this is a capital “J” and not a lowercase “j” which would be used to specify
tar -xJf gnutls.tar.xz tar: invalid option -- J Try `tar --help' or `tar --usage' for more information.
Getting around this is as simple as using the
xz binary to first decompress the file, and then
tar to extract it. If you don’t already have it, you can install
yum -y install xz unxz filename.tar.xz tar -xf filename.tar