When you do gem install
the gem is installed to your default system location for gems (you can get that looking at the output of gem env
).
But when you're doing bundle install
you're installing the gem to a location other than your system's gem repository (as you have configured a custom path for your bundle BUNDLE_PATH=./vendor/bundle
), so Bundler will install the gems even if they're present in the system's gem repository, because you're not using that.
Now, for some reason the gem
command has no trouble locating the system libraries needed to build the native extensions of the gem, but Bundler has. So what you have to do is instruct Bundler the paths for those libraries.
So, assuming you're using Homebrew:
Make sure you have all the native dependencies installed:
brew install libxml2 libxslt libiconv
Instruct Bundler how to build the nokogiri gem:
bundle config build.nokogiri --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
Install the bundle, signaling nokogiri to use the aforementioned libraries:
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install
It should be it.
EDIT:
Although the above steps may remain necessary, it seems that the actual problem is the presence of 'space' characters in your project's path.
Seeing that unsetting the bundle path option make things work, I've reviewed your original bundle install
output more carefully and I've got aware that you're using what it looks like an external drive with 'space' characters on its name.
Project paths including 'space' or especial chars are usually a problem for a lot of tools so you should avoid them. Please try renaming your volume or moving your project to another location.
Sorry I did not realize before.