Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active May 3, 2024 12:20
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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!
@ciiqr
Copy link

ciiqr commented Nov 3, 2022

Really appreciate this! I used your script + https://codemagic.io/ (which runs on m1 macs by default) to get myself a prebuilt binary:
https://github.com/ciiqr/jq-macos-arm

@magnetikonline
Copy link
Author

Ah nice one @ciiqr - happy I could be of help and wasn't aware of codemagic and their use of M1 ARM build instances. πŸ‘

And thanks for leaving a URL credit in your build.sh πŸ˜„.

@azbarcea
Copy link

Nice one! Thank you! πŸ‘

@jbdamask
Copy link

still useful!

@ciiqr
Copy link

ciiqr commented Sep 30, 2023

jq 1.7 released a few weeks back with proper apple silicon support! πŸŽ‰
https://github.com/jqlang/jq/releases/tag/jq-1.7

@magnetikonline
Copy link
Author

Thanks for noting that @ciiqr πŸ‘

@magnetikonline
Copy link
Author

magnetikonline commented Oct 2, 2023

FWIW - greatly simplified install.sh - and building/installing jq v1.7 - no need for all the pesky patching/tweaking to get things to compile anymore. πŸ‘

@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