ruby-vips: Mac OS: LoadError: Could not open library 'vips'

So I did brew upgrade vips that poured the vips-8.5.8_2.el_capitan and now require vips (the gem is the latest one) cause:

LoadError: Could not open library 'vips': dlopen(vips, 5): image not found.
Could not open library '/usr/local/lib/libvips.dylib': dlopen(/usr/local/lib/libvips.dylib, 5): Library not loaded: @rpath/libpoppler.71.dylib
  Referenced from: /usr/local/opt/poppler/lib/libpoppler-glib.8.dylib
  Reason: image not found
	from /Users/nakilon/.gem/gems/ffi-1.9.18/lib/ffi/library.rb:147:in `block in ffi_lib'
	from /Users/nakilon/.gem/gems/ffi-1.9.18/lib/ffi/library.rb:100:in `map'
	from /Users/nakilon/.gem/gems/ffi-1.9.18/lib/ffi/library.rb:100:in `ffi_lib'
	from /Users/nakilon/.gem/gems/ruby-vips-2.0.7/lib/vips.rb:466:in `<module:Vips>'
	from /Users/nakilon/.gem/gems/ruby-vips-2.0.7/lib/vips.rb:457:in `<top (required)>'
$ ls -l /usr/local/lib/libvips.dylib
lrwxr-xr-x  1 nakilon  admin  40 11 окт 19:17 /usr/local/lib/libvips.dylib -> ../Cellar/vips/8.5.8_2/lib/libvips.dylib
$ ls -l /usr/local/lib/libpoppler.dylib 
lrwxr-xr-x  1 nakilon  admin  45 11 окт 19:17 /usr/local/lib/libpoppler.dylib -> ../Cellar/poppler/0.60.1/lib/libpoppler.dylib

Ruby is native to this OS: 2.0.0p648

The thing I’ve noticed about brew is that now it drags some portable Ruby 2.3 – not sure if that’s relevant.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (19 by maintainers)

Commits related to this issue

Most upvoted comments

This worked for me: Macos M1 Rbenv Ruby 3.0.1 Rails 7.0.1

Just ran arch -x86_64 brew install vips and the action_text successfully printed my jpg in trix editor content.

For those who don’t know what arch -x86_64 is, take a look at: https://en.wikipedia.org/wiki/Rosetta_(software)

So as workaround I’ve decided to copy a ruby executable to another directory – for example, a working directory of where I need to run things. Like this:

$ sudo cp /usr/bin/ruby ./
$ chmod 500 ./ruby

Here is how I made things work:

IRB

If you do which irb you’ll see that it’s a ruby script /usr/bin/irb that has hardcoded shebang #!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby so instead of irb you have to do:

$ ./ruby irb

RSPEC

which rspec gives me /Users/nakilon/.gem/bin/rspec and there we see the #!/usr/bin/env ruby that means you don’t have to patch it, just:

$ PATH=`pwd`:$PATH rspec

RAKE

Running rspec via rake is tricky – it is doing it in another way and seems to use the system ruby. How to check it? The only working way to know the exact path to executable by PID on Mac OS I’ve found is https://stackoverflow.com/a/14805946/322020 so you compile it and put the tool nearby. You can see it’s working by:

$ ruby -e 'puts `./pathfind #{Process.pid}`'
proc 19893: /usr/bin/ruby
$ PATH=`pwd`:$PATH ruby -e 'puts `pathfind #{Process.pid}`'
proc 19897: /Users/nakilon/.../ruby
$ PATH=`pwd`:$PATH /usr/bin/env ruby -e 'puts `pathfind #{Process.pid}`'
proc 19900: /Users/nakilon/.../ruby

Now at the bottom of vips issue backtrace we see from /Users/nakilon/.gem/gems/rspec-core-3.5.3/exe/rspec:4. Here its content:

#!/usr/bin/env ruby

require 'rspec/core'
RSpec::Core::Runner.invoke

Right after shebang you add the following line for debug:

puts __FILE__, `/Users/nakilon/.../pathfind #{Process.pid}`

Now when you run the rake again you see:

/Users/nakilon/.gem/gems/rspec-core-3.5.3/exe/rspec
proc 19849: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby

that means shebang is ignored. Open the /usr/bin/rake and add the

require "byebug"
byebug

right before the Rake.application.run – moving down with step and next commands you’ll eventually get to:

[74, 83] in /Users/nakilon/.gem/gems/rspec-core-3.5.3/lib/rspec/core/rake_task.rb
   74:       # @private
   75:       def run_task(verbose)
   76:         command = spec_command
   77:         puts command if verbose
   78: 
=> 79:         return if system(command)
   80:         puts failure_message if failure_message
   81: 
   82:         return unless fail_on_error
   83:         $stderr.puts "#{command} failed" if verbose
(byebug) command
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -I/Users/nakilon/.gem/gems/rspec-support-3.5.0/lib:/Users/nakilon/.gem/gems/rspec-core-3.5.3/lib /Users/nakilon/.gem/gems/rspec-core-3.5.3/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

where the spec_command was:

   141:       def spec_command
   142:         cmd_parts = []
   143:         cmd_parts << RUBY
   144:         cmd_parts << ruby_opts
   145:         cmd_parts << rspec_load_path

The RUBY constant isn’t declared at the moment the byebug starts but it appears immediately after you step into Rake.application.run. If you do the

$ grep -rI "RUBY =" /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/

you’ll find the RUBY = ENV['RUBY'] || File.join( in file_utils.rb that is required by /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake.rb. So the solution is:

$ RUBY=`pwd`/ruby rake

if the default rake task is rspec, and:

$ ./ruby `which rake` my_custom_rask

for simple custom tasks.

Have a look at #130 and try the suggestions… I think it’s a bad install configuration issue and you need to track down where it went wrong.