Could not install nokogiri - ruby

I try to bundle install --gemfile=Gemfile, but error occurs as:
An error occurred while installing nokogiri (1.7.2), and Bundler
cannot continue. Make sure that gem install nokogiri -v '1.7.2'
--source 'http://rubygems.org/' succeeds before bundling.
So I try install nokogiri, then refused:
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
It seems nokogiri was locked. I wonder how to install specific version(1.7.2) of nokogiri.
My OS is Amazon Linux AMI release 2017.09, and I have installed
mysql-devel sqlite-devel libcurl-devel ruby24 ruby24-devel zlib-devel
gcc libxslt-devel libxml2-devel gcc-c++ make curl
Ruby version is 2.4 and bundler at version 1.17.3. Detailed error info is:
current directory: /usr/local/share/ruby/gems/2.4/gems/nokogiri-1.7.2/ext/nokogiri
/usr/bin/ruby2.4 -r ./siteconf20190305-30890-gjsryi.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:
Building Nokogiri with a packaged version of libxml2-2.9.4
with the following patches applied:
- 0001-Fix-comparison-with-root-node-in-xmlXPathCmpNodes.patch
- 0002-Fix-XPointer-paths-beginning-with-range-to.patch
- 0003-Disallow-namespace-nodes-in-XPointer-ranges.patch
Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:
gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.

Related

Cannot install Jekyll after updating to Catalina - An error occurred while installing ffi (1.9.18)

I have updated my mac to use Catalina and now I am having all sorts of issues when I try and install Jekyll.
This is what I get when I run my usual grunt setup:
Running "jekyll:dist" (jekyll) task
>> Error: Command failed: bundle exec jekyll -v
>> bundler: command not found: jekyll
>> Install missing gem executables with `bundle install`
Warning: Please install Jekyll before running this task. Use --force to continue.
I then run sudo bundle install
I then get this:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this
application for all non-root users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Using public_suffix 3.0.1
Using addressable 2.5.2
Using bundler 2.1.4
Using colorator 1.1.0
Fetching ffi 1.9.18
Installing ffi 1.9.18 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Applications/MAMP/htdocs/hangr/vendor/bundle/ruby/2.6.0/gems/ffi-1.9.18/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201016-30905-1yh2cx1.rb extconf.rb
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
checking for ffi_prep_cif_var()... yes
creating extconf.h
creating Makefile
current directory: /Applications/MAMP/htdocs/hangr/vendor/bundle/ruby/2.6.0/gems/ffi-1.9.18/ext/ffi_c
make "DESTDIR=" clean
current directory: /Applications/MAMP/htdocs/hangr/vendor/bundle/ruby/2.6.0/gems/ffi-1.9.18/ext/ffi_c
make "DESTDIR="
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
Call.c:355:5: error: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
^
./Thread.h:78:39: note: expanded from macro 'rbffi_thread_blocking_region'
# define rbffi_thread_blocking_region rb_thread_call_without_gvl
^
1 error generated.
make: *** [Call.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Applications/MAMP/htdocs/hangr/vendor/bundle/ruby/2.6.0/gems/ffi-1.9.18 for inspection.
Results logged to
/Applications/MAMP/htdocs/hangr/vendor/bundle/ruby/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.9.18/gem_make.out
An error occurred while installing ffi (1.9.18), and Bundler cannot continue.
Make sure that `gem install ffi -v '1.9.18' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
jekyll was resolved to 3.4.3, which depends on
jekyll-sass-converter was resolved to 1.5.1, which depends on
sass was resolved to 3.5.5, which depends on
sass-listen was resolved to 4.0.0, which depends on
rb-inotify was resolved to 0.9.10, which depends on
ffi
When I run
ruby -v
I get
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
I have no idea at all what I need to do.
When I run
jekyll -v
I get
-bash: /usr/local/bin/jekyll: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
I tried running this from another post but had no luck
gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"
Does anyone have any ideas?
Thanks
The root problem is that you cannot install one of jekyl's dependancies - specifically the ffi gem. Knowing that will better help you workout a fix.
You can see that this is the error by reading your bundle output. Learn how to read these so you can better help yourself in the future; If you were searching for "install ffi on macOS" you might have found more information available to you.
Give that you've just installed Catalina, it's likely that GCC isn't on your machine, or is outdated, or is unlinked.
Try running xcode-select --install to (re)install the Xcode command line tools.
ALSO - STOP USING SUDO
At the very top of your bundle output is a warning that you shouldn't use sudo when installing gems. It's good advice to follow!
Even better advice would be to use rbenv or rvm to create gem sets or environments for each ruby application you're working with. But, if you don't go all the way down that path, ** at least, stop using sudo**

Error installing nokogiri: invalid gem: package is corrupt

I'm trying to parse a website by using jekyll on my Debian x64 and I get a problem with this following gem nokogiri , in particular I've been required on install the version 1.8.5 , but as it was not working I attempted downloading the last version nokogiri (1.11.0.rc2) Manualy from the web and now I'm stuck with this error.
bundle exec jekyll serve
Could not find nokogiri-1.8.5 in any of the sources
Run `bundle install` to install missing gems.
bundle install
Bundler::GemspecError: Could not read gem at
/var/lib/gems/2.7.0/cache/nokogiri-1.8.5.gem. It may be corrupted.
An error occurred while installing nokogiri (1.8.5), and Bundler
cannot continue.
Make sure that `gem install nokogiri -v '1.8.5' --source
'https://rubygems.org/'` succeeds before bundling.
I think you don't have it's dependancy library libxml2 try running below code.
brew install libxml2
if not worked add nokogiri gem using below command
gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]

gem eventmachine fatal error: 'openssl/ssl.h' file not found

Just installed El Capitan and can't install gem eventmachine 1.0.7. openssl is at 1.0.2a-1. Tried to use --with-ssl-dir but it seems ignored.
Reported it to their github repo as well.
Any suggestions are really appreciated. Thanks.
$ ls /usr/local/Cellar/openssl/1.0.2a-1/include/openssl/ssl.h
/usr/local/Cellar/openssl/1.0.2a-1/include/openssl/ssl.h
$ gem install eventmachine -v '1.0.7' -- --with-ssl-dir=/usr/local/Cellar/openssl/1.0.2a-1/include
/Users/pain/.rbenv/versions/2.1.2/bin/ruby -r ./siteconf20150612-56154-1hsjz2n.rb extconf.rb --with-ssl-dir=/usr/local/Cellar/openssl/1.0.2a-1/include
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_fd_select()... yes
checking for rb_fdset_t in ruby/intern.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue... yes
checking for clock_gettime()... no
checking for gethrtime()... no
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:116:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
^
1 error generated.
make: *** [binder.o] Error 1
make failed, exit code 2
$ gem install eventmachine -- --with-cppflags=-I/usr/local/opt/openssl/include
Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include'
This could take a while...
Successfully installed eventmachine-1.0.8
1 gem installed
You can also set up bundler like this but I think that is superficial
bundle config build.eventmachine --with-cppflags=-I/usr/local/opt/openssl/include
When using bundler and homebrew:
$ bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include
$ bundle install
brew link --force openssl
Then:
gem install eventmachine
It also fixes:
gem install taks
bundle install
rake and rails tasks
P.S. Probably you'll need to remove and run brew install openssl again
The issue happends because Apple had removed openssl from OSX (in El Captain build)
gem pristine eventmachine -- --with-cppflags=-I/usr/local/opt/openssl/include
pristine removes the old gem and recompiles it.
The cpp flags option allows the compiler to find the openssl headers.
If you prefer to abstract away the cpp flags argument, you can do the following:
PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig"
You can also add the version if you like:
gem pristine eventmachine -v '1.0.4' -- --with-cppflags=-I/usr/local/opt/openssl/include
I was trying to install v 1.0.3 and this worked for me.
gem install eventmachine -v '1.0.3' -- --with-cppflags=-I/usr/local/opt/openssl/include
These discussions were very helpful: https://github.com/eventmachine/eventmachine/issues/602
This assumes the machine already has openssl installed via brew.
This solved the problem for me:
PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig" gem install eventmachine -v "1.0.8"
Source: https://github.com/sj26/mailcatcher/issues/254
If you're installing EventMachine as a dependency of another gem, be sure to specify the correct version when you manually install the gem:
gem install eventmachine -v 1.0.5 -- --with-cppflags=-I$(brew --prefix openssl)/include
Then you can install the gem that you were originally trying to install:
gem install mailcatcher
One alternative is to add a bundler config entry for your whole user profile, like this:
cd ~
bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include
it'll create a .bundle/config file in your home directory, which is then used in all your projects when you run bundle install.
This looks like a more recent issue: https://github.com/eventmachine/eventmachine/issues/936
I solved this problem on macOS 12.3.1 with the following:
M1 Max:
gem install eventmachine -- --with-openssl-dir=/opt/homebrew/Cellar/openssl#1.1/1.1.1n/
Intel:
gem install eventmachine -- --with-openssl-dir=/usr/local/Cellar/openssl#1.1/1.1.1n/
This worked for me -
gem install eventmachine -v '1.0.7' -- --debug --backtrace --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
Building native extensions with: '--debug --backtrace --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib'
This could take a while...
Successfully installed eventmachine-1.0.7
Parsing documentation for eventmachine-1.0.7
Installing ri documentation for eventmachine-1.0.7
Done installing documentation for eventmachine after 9 seconds
1 gem installed
NOTE:- Before I was able to successfully install this gem, I had to do a few things. These might apply to you, so listing them here -
1.) got off the corporate-VPN
OR you might have to turn ON proxy settings
2.) PKG_CONFIG_PATH was set to -
echo $PKG_CONFIG_PATH
/usr/local/opt/openssl/lib/pkgconfig
3.) had to add the following to $PATH in bash_profile (in my case ~/.zshrc)
export PATH="/usr/local/opt/openssl/bin:$PATH"
4.) Also note, that contrary to some answers I got in this SO post, and also this thread on github-eventmachine, I was not able to install eventmachine
gem install eventmachine -v '1.0.7' -- --debug --backtrace --with-cppflags=-I/usr/local/include --with-ldflags=-L/usr/local/lib
Fetching: eventmachine-1.0.7.gem (100%)
Building native extensions with: '--debug --backtrace --with-cppflags=-I/usr/local/include --with-ldflags=-L/usr/local/lib'
This could take a while...
ERROR: Error installing eventmachine:
ERROR: Failed to build gem native extension.
It seems /usr/local/opt/openssl/include is the right location and not /usr/local/include when specifying the openssl location.
This installed it for me:
gem install eventmachine -- --with-openssl-dir=/usr/local/opt/openssl#1.1
I got it from the eventmachine Github repo. Evidently OpenSSL tools were moved / removed from MacOS at some point.
In my case, I wanted to install something else (mailcatcher) with a dependency on eventmachine. I did this by replacing eventmachine with mailcatcher in the above command.
I met the same eventmachine issue and the answers above didn't work for me, finally reinstall ruby with given openssl version works:
rvm reinstall 3.1.2 --with-openssl-dir=/usr/local/opt/openssl#3
For Jekyll and Fish:
gem install jekyll -- --with-cppflags=-I(brew --prefix openssl)/include
As of 2022, the way to install eventmachine, assuming brew install openssl has already installed successfully, is: gem install eventmachine -- --with-cppflags=-I/opt/homebrew/opt/openssl/include
Notice that the include directory has moved.
With openssl#3 with Homebrew it worked by running this command:
gem install eventmachine -- --with-openssl-dir=/usr/local/opt/openssl#3/bin/openssl
NOTE the /bin/openssl at the end which made the difference for me.

Ruby: Having correct DevKit and Ruby version - Failed to build gem native extension

I installed 1.9.3 ruby from http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-1.9.3-p448.exe to C:\Ruby193.
I downloaded https://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe to C:\ruby_dev_kit and from there ran ruby dk.rb init then ruby dk.rb install
It all installed successfully.
Then when I ran gem install json I keep getting
Installing json (1.4.6) The system cannot find the path specified.
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
checking for ruby/re.h... yes
checking for ruby/encoding.h... yes
creating Makefile
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.4.
6 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.4.6/ext/json/ext/ge
nerator/gem_make.out
An error occurred while installing json (1.4.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.4.6'` succeeds before bundling.
I also tried gem install json --platform=ruby
Doesn't change anything. It seems that there's c compiler issues but I path defined correctly and DevKit associated as well.
Tried uninstall and install, doesn't help. Any thoughts?

Why isn't Nokogiri installing?

I'm having trouble installing Nokogiri. When I run bundle install or gem install nokogiri the installation fails.
The error I'm getting is:
(Note: This failure is from using the installation command on nokogiri.org)
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/roneesh/.rbenv/versions/1.9.3-p194/bin/ruby extconf.rb --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28/ --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Extracting libxml2-2.8.0.tar.gz into tmp//ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... ERROR, review 'tmp//ports/libxml2/2.8.0/configure.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
The command I'm trying to use is:
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28/ --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
I have installed xml2, xslt and libiconv all with brew, and put in their proper versions above. Still no resolution. The only thing I haven't done is libiconv from source (my wget command isn't working for some reason).
You need to specify nokogiri to use the system libraries instead, so it doesn't try to build them itself.
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install
Answer found here: Error installing nokogiri 1.6.0 on mac (libxml2).
Setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 also did the trick for me, but I had to install the native libraries the gem depends on first (I did it with Homebrew) and then tell the gem to use them.
Summarising:
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install 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"

Resources