This worked for me, as Simar mentioned.
sudo gem install rails -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/
And if you have any problems, install it on a Mac, please check here. https://gorails.com/setup/osx/10.11-el-capitan
Also, if you could not find / usr / local / Cellar / libxml 2 / existing, you might need his homework.
brew install libxml2
If you install it on a recently installed X EL CAPITAN OS, like me, you will probably find that homebrew tells you that libxml2 is already installed and brew will not replace the existing libxml2, it recently installed the one located in / usr / local / Cellar / libxml 2 /, which we must link to the libraries. Because the system default libxml2 will not bind successfully.
source share