Skip to content

Instantly share code, notes, and snippets.

@harry-wood
Last active April 9, 2023 17:04
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 harry-wood/83b9c2c07b604524a23a4d2b88584a0f to your computer and use it in GitHub Desktop.
Save harry-wood/83b9c2c07b604524a23a4d2b88584a0f to your computer and use it in GitHub Desktop.
Installing libxml on mac for ruby.md

Installing/debugging libxml on mac for ruby/rails

Install xcode command line tools (or check if they're already installed)

xcode-select --install

Do we have libxml installed already?

xsltproc --version

(A libxml version of "20904" means "2.9.4")

Try building the gem against the system libxml headers. Configure bundler like so.

bundle config --global build.libxml-ruby --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2
bundle install

Failing on the libxml-ruby gem?

Try libxml with homebrew (it will be installed in addition to the system libxml):

brew install libxml2
brew link --force libxml2

Check where it installed it (normally /usr/local/opt/libxml2)

brew --prefix libxml2

Add it to your path by editing your ~/.zshrc file. Add this line on the end:

export PATH="/usr/local/opt/libxml2/bin:$PATH"

Configure bundler like so and try the build again.

bundle config --global build.libxml-ruby --with-xml2-include=`brew --prefix libxml2`/usr/include/libxml2
bundle install

Or try to install the libxml-ruby gem more directly.

gem install libxml-ruby -- --with-xml2-dir=`brew --prefix libxml2` --with-xml2-config=`brew --prefix libxml2`/bin/xml2-config

Improve this doc?

The above is an agglomeration of tips I've found on sites listed below. I think ideally we would offer more commands/tips to help people check which bits are working step-by-step as they go along. It's useful to think about how to get it working for someone with a fresh macbook, and also for someone with a mess of aborted attempts at installing. Suggestions welcome!

Ref

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