ruby-vips: Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory

Firstly thanks for vips and this gem! Great work.

Whilst writing this up, I’m not 100% sure this is the right place to ask for help but the error is the same as similar issues:

https://github.com/libvips/ruby-vips/issues/176 https://github.com/libvips/ruby-vips/issues/187

LoadError: Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory.
Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory

ruby-vips ‘2.0.17’ ruby ‘~> 2.5.7’ ffi - 1.11.3

I’ve tried multiple build packs to get ruby-vips deployed on heroku.

https://elements.heroku.com/buildpacks/brandoncc/heroku-buildpack-vips https://elements.heroku.com/buildpacks/alex88/heroku-buildpack-vips https://elements.heroku.com/buildpacks/verumex/heroku-buildpack-libvips

And building my own debian packages by following this blog

https://renchap.com/blog/post/building_recent_libvips_on_debian/

https://dronebase-buildpacks.s3.amazonaws.com/libvips-dev_8.6.3-1_amd64.deb https://dronebase-buildpacks.s3.amazonaws.com/libvips-tools_8.6.3-1_amd64.deb https://dronebase-buildpacks.s3.amazonaws.com/libvips42_8.6.3-1_amd64.deb

However this is the latest from heroku build logs…

-----> Detecting rake tasks
 !
 !     Could not detect rake tasks
 !     ensure you can run `$ bundle exec rake -P` against your app
 !     and using the production group of your Gemfile.
 !     rake aborted!
 !     LoadError: Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory.
 !     Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory

I have got this running locally with ‘rails s’ and managed to tile my high res image. However if a try and launch my server with foreman and sidkiq workers it fails to launch with:

23:39:11 assets_worker.1       | /bundle/gems/ffi-1.11.3/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory. (LoadError)
23:39:11 assets_worker.1       | Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory
23:39:11 assets_worker.1       | 	from /bundle/gems/ffi-1.11.3/lib/ffi/library.rb:99:in `map'
23:39:11 assets_worker.1       | 	from /bundle/gems/ffi-1.11.3/lib/ffi/library.rb:99:in `ffi_lib'
23:39:11 assets_worker.1       | 	from /bundle/gems/ruby-vips-2.0.17/lib/vips.rb:528:in `<module:Vips>'
23:39:11 assets_worker.1       | 	from /bundle/gems/ruby-vips-2.0.17/lib/vips.rb:525:in `<top (required)>'
23:39:11 assets_worker.1       | 	from /bundle/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:274:in `require'
23:39:11 assets_worker.1       | 	from /bundle/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:274:in `block in require'
23:39:11 assets_worker.1       | 	from /bundle/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:240:in `load_dependency'
23:39:11 assets_worker.1       | 	from /bundle/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:274:in `require'
23:39:11 assets_worker.1       | 	from /bundle/gems/ruby-vips-2.0.17/lib/ruby-vips.rb:1:in `<top (required)>'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:81:in `require'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:76:in `each'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:76:in `block in require'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:65:in `each'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:65:in `require'
23:39:11 assets_worker.1       | 	from /var/lib/gems/2.5.0/gems/bundler-1.17.3/lib/bundler.rb:114:in `require'
23:39:11 assets_worker.1       | 	from /home/app/Sake/config/application.rb:16:in `<top (required)>'
23:39:11 assets_worker.1       | 	from /bundle/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:280:in `require'
23:39:11 assets_worker.1       | 	from /bundle/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:280:in `boot_system'
23:39:11 assets_worker.1       | 	from /bundle/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:46:in `run'
23:39:11 assets_worker.1       | 	from /bundle/gems/sidekiq-5.2.7/bin/sidekiq:12:in `<top (required)>'
23:39:11 assets_worker.1       | 	from /bundle/bin/sidekiq:29:in `load'
23:39:11 assets_worker.1       | 	from /bundle/bin/sidekiq:29:in `<main>'

Any tips would be appreciated. THanks

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 35 (10 by maintainers)

Most upvoted comments

So I had the same problem on Heroku, took me a couple of hours to get this running. I am not using Docker.

I added this buildpack to my app: heroku buildpacks:add heroku-community/apt --index 1

And the Aptfile in my root directory contains:

libglib2.0-0
libglib2.0-dev
libpoppler-glib8
libheif-dev
libvips-dev
libvips

Note: This added 140MB to my slug size, but at least it runs now.

Hello @jrae,

Sorry, I’m not a Heroku expert 😦

Where does your libvips.so.42 end up? If it’s in one of the standard locations, you’ll need to run ldconfig before ruby-vips can find it. If it’s in a non-standard location, you’ll need to set LD_LIBRARY_PATH to that directory.

I’ve made a dockerfile which builds and tests ruby-vips with the latest libvips on heroku18, if that’s any help:

https://github.com/jcupitt/docker-builds/tree/master/ruby-vips-heroku18

You’ll probably want to add some other loaders. It makes a libvips installed to /usr/local/vips, so it needs LD_LIBRARY_PATH to be set to /usr/local/vips/lib.

Ran into this problem upgrading rails 6 to 7, this solved the problem. Followed the steps given with a little tweek to the Aptfile, I used:

libglib2.0-0
libpoppler-glib8
libvips

Instead so the slug size would be smaller by about 40mb

brew install vips (which to my big surprise installed the other half of the entire Internet)

Yes, the homebrew vips package installs every possible libvips dependency. I queried this and the homebrew devs said they don’t want it to fall back to building from source, so they don’t want to omit any options at all if possible.

It means you can’t use the homebrew binary on untrusted data, but probably no one does.

That message is definitely due to not having vips installed. One, does it work locally for you?

Regarding Heroku, what does your aptfile look like?

On Aug 17, 2022, at 10:06 AM, Walther Diechmann @.***> wrote:

wauw - that was fast 😃

% gem list | grep ffi ffi (1.15.5) public_suffix (4.0.7, 4.0.6) %

I use gem ‘image_processing’ which translates into

image_processing (1.12.2)
  mini_magick (>= 4.9.5, < 5)
  ruby-vips (>= 2.0.17, < 3)

and what is even worse - doing a which vips on my MBAir M1 tells me that I don’t have one - 😮

that, however, should not hinder me deploying - or?

— Reply to this email directly, view it on GitHubhttps://github.com/libvips/ruby-vips/issues/219#issuecomment-1218058533, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADTGUW5QSZVB56C7YZMONV3VZTWXDANCNFSM4KFPCQIA. You are receiving this because you commented.Message ID: @.***>

I fixed up my docker build a bit:

https://github.com/jcupitt/docker-builds/tree/master/libvips-heroku18

It makes a 4MB tarball which runs on a bare heroku image and includes most useful file formats (including PDF, via PDFium) and disables all the dubious ones. The README has some notes.

With this test dockerfile:

FROM heroku/heroku:18

RUN apt-get update \
    && apt-get install -y ruby-dev

COPY libvips-heroku18.tar.gz /usr/local/src

RUN cd /usr/local/lib \
    && tar xf /usr/local/src/libvips-heroku18.tar.gz \
    && ldconfig 

RUN gem install ruby-vips

RUN ruby -e 'require "vips"; puts "ruby-vips: libvips #{Vips::LIBRARY_VERSION}"'

I see:

$ docker build -t libvips-heroku:18 -f Dockerfile.test .
Sending build context to Docker daemon   4.05MB
Step 1/6 : FROM heroku/heroku:18
...
---> 9beef2c73619
Step 6/6 : RUN ruby -e 'require "vips"; puts "ruby-vips: libvips #{Vips::LIBRARY_VERSION}"'
 ---> Running in f9980c32c39c
ruby-vips: libvips 8.12.2-Tue Jan 25 09:34:32 UTC 2022
Removing intermediate container f9980c32c39c
 ---> fda0e87ba4fa
Successfully built fda0e87ba4fa
Successfully tagged libvips-heroku:18

Thanks @jcupitt — I’ve seen your wisdom and many comments across a multitude of Vips libraries, packages, adapters, etc. and just wanted to give a proper thank you for all of your efforts 🙂

With Rails 7 now defaulting active storage to Vips > ImageMagick I imagine there’s going to be a lot more uptake. I tried brandoncc’s buildpack but was getting errors from it (same as these) so ended up just going the full-apt route.

Hello @jrae,

Sorry, I’m not a Heroku expert 😦

Where does your libvips.so.42 end up? If it’s in one of the standard locations, you’ll need to run ldconfig before ruby-vips can find it. If it’s in a non-standard location, you’ll need to set LD_LIBRARY_PATH to that directory.

I’ve made a dockerfile which builds and tests ruby-vips with the latest libvips on heroku18, if that’s any help:

https://github.com/jcupitt/docker-builds/tree/master/ruby-vips-heroku18

You’ll probably want to add some other loaders. It makes a libvips installed to /usr/local/vips, so it needs LD_LIBRARY_PATH to be set to usr/local/vips/lib.

Thanks John, its work properly…

Finally found this buildpack which allows me to deploy with heroku-16 (behind due to other dependency issues).

https://github.com/zoras/heroku-buildpack-libvips

Thanks @zoras!

However I’m now seeing

Vips::Error: VipsOperation: class "dzsave" not found

At runtime. Tried installing

http://ftp.acc.umu.se/pub/GNOME/sources/libgsf/1.14/libgsf-1.14.46.tar.xz

with .vendor_urls based on this comment.

https://github.com/libvips/pyvips/issues/65#issuecomment-423081974

Still no joy. Will edit this comment when I find a solution.