'Could not open library 'vips.42'; Could not open library 'libvips.42.dylib'

When upgrading from rails 6 to rails 7, and running some ActiveStorage methods locally, I see:

Could not open library 'vips.42': dlopen(vips.42, 0x0005): tried: 'vips.42' (no such file), '/usr/local/lib/vips.42' (no such file), '/usr/lib/vips.42' (no such file), '/Users/st/rails/myapp/vips.42' (no such file), '/usr/local/lib/vips.42' (no such file), '/usr/lib/vips.42' (no such file). (LoadError)
Could not open library 'libvips.42.dylib': dlopen(libvips.42.dylib, 0x0005): tried: 'libvips.42.dylib' (no such file), '/usr/local/lib/libvips.42.dylib' (no such file), '/usr/lib/libvips.42.dylib' (no such file), '/Users/st/rails/myapp/libvips.42.dylib' (no such file), '/usr/local/lib/libvips.42.dylib' (no such file), '/usr/lib/libvips.42.dylib' (no such file)

There are a number of GitHub issues with similar: (e.g. here).

I am not sure if I need to install the ruby-vips gem or if there's something problematic with my OS / shared libs.

Note some others have reported the same error. I wonder if it could be a bug?



Solution 1:[1]

If you have this problem on your local machine..

If you have just upgraded from rails 6 to 7, and have config.load_defaults 7.0 set in config/application.rb, then your app will use vips by default.

If that's what you want, just make sure vips is installed locally. You can install it with homebrew (thanks to @timroman for this info):

brew install vips

However, if you don't want to use vips, and prefer to use mini_magick as in rails 6, just include this line in config/application.rb

config.active_storage.variant_processor = :mini_magick

Notes

  • Moving from using :mini_magick to :vips will probably require code changes to make your application work as expected. See here for info on that.
  • Further reading:

If you're having problems with vips on heroku..

If you get a similar issue on heroku, make sure everything works fine locally first (if it doesn't, see above), then to solve the issues on heroku, try the following 3 steps:

  1. Add gem "ruby-vips" to your gemfile if it isn't already there

  2. Set these two buildpacks (in addition to any you already have, in this example I was also using the heroku/ruby buildpack, hence why it's included as the last buildpack):

heroku-community/apt
https://github.com/brandoncc/heroku-buildpack-vips
heroku/ruby

I think the order here matters (if you have other buildpacks, best to add them after the first two). You can set buildpacks like this

heroku buildpacks:set --index=1 heroku-community/apt
heroku buildpacks:set --index=2 https://github.com/brandoncc/heroku-buildpack-vips
  1. Create a file in the root directory of your app called Aptfile with this as the contents:
libglib2.0-0
libglib2.0-dev
libpoppler-glib8

Notes:

  • You may wish to add more libraries to the Aptfile depending on what processing needed exactly (for example, pdf processing). Here's an example of an Aptfile with more libraries included. And here is the rails guide showing which other things you may need.
  • Further reading:
    • Info on vips buildpack in this thread.
    • See here for vips buildpack
    • See here for information about the apt buildpack and Aptfile

Solution 2:[2]

For Linux users just install using apt install libvips, if want to keep using the default load of Rails 7.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jean Barbosa