Skip to content

Instantly share code, notes, and snippets.

@fscm
Last active January 31, 2025 12:20
Show Gist options
  • Save fscm/cae2c3537d282e13913e50ca8908582d to your computer and use it in GitHub Desktop.
Save fscm/cae2c3537d282e13913e50ca8908582d to your computer and use it in GitHub Desktop.
[macOS] Install GNU Tar tool from source

[macOS] Install GNU Tar tool from source

Instructions on how to install the gtar command on macOS from source.

Prerequisites

macOS Command Line Tools need to be installed on your local computer.

To install the Command Line Tools run the following command:

xcode-select --install

Get the source

To obtain the GNU Tar tool source code run the following commands:

mkdir -p ~/.src/gtar
curl --silent --location --retry 3 "https://ftp.gnu.org/gnu/tar/tar-1.35.tar.gz" | tar xz --no-same-owner --strip-components=1 -C ~/.src/gtar
cd ~/.src/gtar

Configure

To configure the source to be compiled for macOS run the following commands:

LDFLAGS="-liconv" ./configure --quiet --prefix=/usr/local --program-prefix=g --disable-nls --disable-dependency-tracking

Build

To build the source code run the following command:

make --silent --no-print-directory

Install

To install the tool run the following commands:

sudo make --silent --no-print-directory install

Verify

Run the following command on a terminal window:

gtar --version

Clean up

After installing the tool you can remove the downloaded source code using the following commands:

cd ~
rm -rf ~/.src

Replace the default tar command:

To replace the default tar command on macOS with the gtar command just installed run the following commands:

sudo ln -s gtar /usr/local/bin/tar
sudo ln -s gtar.1 /usr/local/share/man/man1/tar.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment