Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active May 3, 2024 12:20
Show Gist options
  • Save magnetikonline/58eb344e724d878345adc8622f72be13 to your computer and use it in GitHub Desktop.
Save magnetikonline/58eb344e724d878345adc8622f72be13 to your computer and use it in GitHub Desktop.
Install jq on macOS from source.

Install jq on macOS from source

Note: as of jq v1.7 the project offers pre-built native macOS releases for ARM64 based architechtures.

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

  • autoconf.
  • automake.
  • libtool
  • jq - from source.

The aim/need was to create an M1 (ARM64) compile of jq - which isn't wasn't (until September 2023) available via releases and avoid using Homebrew.

Tested successfully under a Apple M1 Pro MacBook running macOS Monterey 12.4.

Will likely require Xcode CLI tools. Can be installed via the following:

$ xcode-select --install

Enjoy!

Reference

#!/bin/bash -e
INSTALL_BASE="/usr/local"
AUTOCONF_ARCHIVE="autoconf-2.71"
AUTOCONF_URL="http://ftpmirror.gnu.org/autoconf/$AUTOCONF_ARCHIVE.tar.gz"
AUTOMAKE_ARCHIVE="automake-1.16.5"
AUTOMAKE_URL="http://ftpmirror.gnu.org/automake/$AUTOMAKE_ARCHIVE.tar.gz"
LIBTOOL_ARCHIVE="libtool-2.4.7"
LIBTOOL_URL="http://ftpmirror.gnu.org/libtool/$LIBTOOL_ARCHIVE.tar.gz"
JQ_ARCHIVE="jq-1.7"
JQ_URL="https://github.com/jqlang/jq/releases/download/$JQ_ARCHIVE/$JQ_ARCHIVE.tar.gz"
# build and install autoconf
curl --location --remote-name --silent "$AUTOCONF_URL"
tar --extract --file "$AUTOCONF_ARCHIVE.tar.gz"
pushd "$AUTOCONF_ARCHIVE"
./configure --prefix="$INSTALL_BASE"
make
sudo make install
popd
# build and install automake
curl --location --remote-name --silent "$AUTOMAKE_URL"
tar --extract --file "$AUTOMAKE_ARCHIVE.tar.gz"
pushd "$AUTOMAKE_ARCHIVE"
./configure --prefix="$INSTALL_BASE"
make
sudo make install
popd
# build and install libtool
curl --location --remote-name --silent "$LIBTOOL_URL"
tar --extract --file "$LIBTOOL_ARCHIVE.tar.gz"
pushd "$LIBTOOL_ARCHIVE"
./configure --prefix="$INSTALL_BASE" --disable-dependency-tracking --enable-ltdl-install
make
sudo make install
popd
# build and install jq
curl --location --remote-name --silent "$JQ_URL"
tar --extract --file "$JQ_ARCHIVE.tar.gz"
pushd "$JQ_ARCHIVE"
./configure --prefix="$INSTALL_BASE" --disable-maintainer-mode --with-oniguruma=builtin
make
sudo make install
popd
jq --version
# done!
@gaussye
Copy link

gaussye commented May 3, 2024

hi after running your script JQ can run well but i found that the nodejs can not run properly...
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
LIBTOOL-STATIC Release/tree_sitter.a
Usage: /usr/local/bin/libtool [OPTION]... [MODE-ARG]...
Try 'libtool --help' for more information.
libtool: error: unrecognised option: '-static'

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 8 ]
CXX(target) Release/obj.target/nortti/src/external_copy/serializer_nortti.o
CXX(target) Release/obj.target/nortti/src/isolate/allocator_nortti.o
In file included from ../src/external_copy/serializer_nortti.cc:1:
In file included from ../src/external_copy/serializer.h:2:
In file included from ../src/external_copy/external_copy.h:2:
/Users/ypy/Library/Caches/node-gyp/18.20.2/include/node/v8.h:21:10: fatal error: 'memory' file not found
#include
^~~~~~~~
In file included from ../src/isolate/allocator_nortti.cc:1:
In file included from ../src/isolate/allocator.h:2:
/Users/ypy/Library/Caches/node-gyp/18.20.2/include/node/v8.h:21:10: fatal error: 'memory' file not found

Any ideas? Seems it overwrites the default setting of CommandLineTools. Any way to rollback the changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment