Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active May 12, 2023 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnetikonline/3aeefc1aee8f5d9387ce2de334eae9fd to your computer and use it in GitHub Desktop.
Save magnetikonline/3aeefc1aee8f5d9387ce2de334eae9fd to your computer and use it in GitHub Desktop.
macOS - Install The Silver Searcher (`ag`) from source.

Install The Silver Searcher (ag) on macOS from source

A quick n' dirty bash script to install the following:

  • automake, pkg-config, PCRE, xz - all needed by ag configure.
  • ag - from source.

Requires as a minimum Xcode CLI tools (don't need a full Xcode install). Can be done via the following:

$ xcode-select --install

Enjoy!

Reference

#!/bin/bash -e
INSTALL_BASE="/usr/local"
AG_ARCHIVE="2.2.0"
AG_URL="https://github.com/ggreer/the_silver_searcher/archive/$AG_ARCHIVE.tar.gz"
AUTOMAKE_ARCHIVE="automake-1.16"
AUTOMAKE_URL="http://ftpmirror.gnu.org/automake/$AUTOMAKE_ARCHIVE.tar.gz"
PKGCONFIG_ARCHIVE="pkg-config-0.29.2"
PKGCONFIG_URL="https://pkg-config.freedesktop.org/releases/$PKGCONFIG_ARCHIVE.tar.gz"
PCRE_ARCHIVE="pcre-8.44"
PCRE_URL="https://ftp.pcre.org/pub/pcre/$PCRE_ARCHIVE.tar.gz"
XZ_ARCHIVE="xz-5.2.5"
XZ_URL="https://tukaani.org/xz/$XZ_ARCHIVE.tar.gz"
# build and install automake
curl --location --remote-name "$AUTOMAKE_URL"
tar --extract --file "$AUTOMAKE_ARCHIVE.tar.gz"
pushd "$AUTOMAKE_ARCHIVE"
./configure
make
sudo make install
popd
# build and install pkg-config
curl --location --remote-name "$PKGCONFIG_URL"
tar --extract --file "$PKGCONFIG_ARCHIVE.tar.gz"
pushd "$PKGCONFIG_ARCHIVE"
./configure --with-internal-glib
make
sudo make install
popd
# build and install PCRE
curl --location --remote-name "$PCRE_URL"
tar --extract --file "$PCRE_ARCHIVE.tar.gz"
pushd "$PCRE_ARCHIVE"
pcreVer=${PCRE_ARCHIVE/#pcre-/}
./configure --enable-jit --prefix="$INSTALL_BASE/pcre/${pcreVer/./_}"
make
sudo make install
popd
# build and install xz
curl --location --remote-name "$XZ_URL"
tar --extract --file "$XZ_ARCHIVE.tar.gz"
pushd "$XZ_ARCHIVE"
./configure
make
sudo make install
popd
# build and install ag
curl --location --remote-name "$AG_URL"
tar --extract --file "$AG_ARCHIVE.tar.gz"
pushd "the_silver_searcher-$AG_ARCHIVE"
./build.sh
sudo make install
popd
ag --version
# done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment