Skip to content

Instantly share code, notes, and snippets.

@faun
Last active October 2, 2018 06:50
Show Gist options
  • Save faun/e4ee6158586a3e28e6d4 to your computer and use it in GitHub Desktop.
Save faun/e4ee6158586a3e28e6d4 to your computer and use it in GitHub Desktop.
Install Nokogiri with Homebrew
#! /bin/sh
set -e
BREW_PREFIX="$(brew --prefix)"
BREW_CELLAR="${BREW_PREFIX}/Cellar"
function libxslt_version()
{
brew list --versions libxslt | awk '{ print $2 }'
}
function libxml2_version()
{
brew list --versions libxml2 | awk '{ print $2 }'
}
if [[ (($(libxml2_version) > "2.9.0")) ]]; then
echo "libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs."
echo "Try running the following:"
echo " brew uninstall --force libxml2"
echo " brew install https://raw.githubusercontent.com/Homebrew/homebrew/763d94665ca439653a27ea03da87af96ba66f5b4/Library/Formula/libxml2.rb"
exit -1
fi
function install_nokogiri_gem()
{
printf "Installing nokogiri gem"
if [ "$#" -ne 0 ]; then
printf " with options: '$*'"
fi
echo
gem install nokogiri $* -- \
--with-xml2-include=${BREW_CELLAR}/libxml2/"$(libxml2_version)"/include/libxml2 \
--with-xml2-lib=${BREW_CELLAR}/libxml2/"$(libxml2_version)"/lib \
--with-xslt-dir=${BREW_CELLAR}/libxslt/"$(libxslt_version)"
}
if [[ -n "$(libxslt_version)" && -n "$(libxml2_version)" ]]; then
install_nokogiri_gem "$@"
else
echo "Installing nokogiri dependencies"
brew install https://raw.githubusercontent.com/Homebrew/homebrew/763d94665ca439653a27ea03da87af96ba66f5b4/Library/Formula/libxml2.rb && \
brew install libxslt && \
install_nokogiri_gem "$@"
fi
    curl -o install_nokogiri.sh https://gist.githubusercontent.com/faun/e4ee6158586a3e28e6d4/raw/165c17205b321a4f92060571da45d82f2106da0e/install_nokogiri_with_homebrew
    chmod u+x install_nokogiri.sh
    ./install_nokogiri.sh
    # Install a specific version of nokogiri with:
    # ./install_nokogiri.sh -v '1.6.6.2'
@faun
Copy link
Author

faun commented Jul 5, 2017

This script has been deprecated. Nokogiri now comes with vendored versions of libxml2 and libxslt.

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