Linux / OS X tar incompatibility – tarballs created on OS X give errors when untarred in Linux

I Googled for the error message and it seems like a BSD tar vs. GNU tar issue.

Install GNU tar if you can on Mac OS and use that to create the tar.


If you are using Mavericks or newer, then gnutar is no longer included by default.

The work around, if you use homebrew, is to execute the following:

brew install gnu-tar

You can then use the command gtar for linux compatability.


If you want to replace tar with gtar, simply replace the symlink

tar --version
ll `which tar`
sudo unlink `which tar`
sudo ln -s `which gtar` /usr/bin/tar
tar --version

To restore the original tar provided with Mac Os X, run the above commands but replace which gtar with which bsdtar

Source:
https://github.com/jordansissel/fpm/issues/576


GNU tar doesn't like some of the optional information the default OSX BSD tar includes.

GNU tar will let you suppress those warnings with the option:

--warning=no-unknown-keyword

See: https://www.gnu.org/software/tar/manual/html_section/tar_27.html

Note that BSD tar doesn't support that flag so if you need to run the same unpacking code on all platforms you can use something like:

isGnuTar=$(tar --version | grep -q 'gnu')
if [ $? -eq 0 ]
then
    echo "Detected GNU tar"
    tar --warning=no-unknown-keyword -zxf my.tar.gz
else
    tar -zxf my.tar.gz
fi