Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active Text / Active Storage: vips.so.42: cannot open shared object file: No such file or directory #43976

Closed
overdrivemachines opened this issue Dec 22, 2021 · 11 comments · May be fixed by #44991

Comments

@overdrivemachines
Copy link

overdrivemachines commented Dec 22, 2021

Steps to reproduce

I encountered this error while following DHH's youtube video "Rails 7: The Demo" at 9:10. I have a fresh install of Ubuntu 20.04 and RoR. I got the same error on another computer with a freshly installed Ubuntu and RoR. Here are the steps:

  1. Install action_text and add a rich_text_area to a form.
  2. Run rails server
  3. add some text and image to the rich text and hit submit (just like in the video)

Expected behavior

contents of form get saved normally along with image getting uploaded.

Actual behavior

Rails server quits and I see the following error:

...
...
#<Thread:0x00007fd7113596f8 /home/dynamic/.rvm/gems/ruby-3.0.2/gems/actionpack-7.0.0/lib/action_controller/metal/live.rb:340 run> terminated with exception (report_on_exception is true):
/home/dynamic/.rvm/gems/ruby-3.0.2/gems/ffi-1.15.4/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)
Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory
	from /home/dynamic/.rvm/gems/ruby-3.0.2/gems/ffi-1.15.4/lib/ffi/library.rb:99:in `map'
	from /home/dynamic/.rvm/gems/ruby-3.0.2/gems/ffi-1.15.4/lib/ffi/library.rb:99:in `ffi_lib'
	from /home/dynamic/.rvm/gems/ruby-3.0.2/gems/ruby-vips-2.1.4/lib/vips.rb:573:in `<module:Vips>'
	from /home/dynamic/.rvm/gems/ruby-3.0.2/gems/ruby-vips-2.1.4/lib/vips.rb:570:in `<main>'
...
...

System configuration

Rails version: 7.0.0

Ruby version: 3.0.3

What fixed the issue:

I installed ImageMagick and libvips: sudo apt install imagemagick libvips and the error went away and everything works normally. It took me a long time to figure that out. I hope there is a more appropriate error message when ImageMagick and libvips are not installed on the computer. The error message should clearly ask the user to install ImageMagick to proceed. This will save a lot of frustration and time.

@diabolo
Copy link

diabolo commented Dec 23, 2021

Similar issue here.

I think that a reason this error might happen is that turbo is not installed. In the YouTube video hotwire is installed by default. For three of my attempts following along with rails 7 it wasn't. If its not installed running

rails importmap:install
rails turbo:install:importmap

Doing the turbo install adds a number of gems.

Installing mini_magick 4.11.0
Installing ruby-vips 2.1.4
Fetching image_processing 1.12.1
Installing image_processing 1.12.1

which may fix the issue. I did update imagemagick and install Vips, and I've just done another version of the blog app and now hotwire is installing by default! Not sure if the two things are related.

@ghiculescu
Copy link
Member

@overdrivemachines could you share a sample app that reproduces the issue? It'd be good to confirm what gems are present.

@jcowhigjr
Copy link

jcowhigjr commented Dec 26, 2021

To reproduce: I was also following DHH guide using the latest Dockerfile with the default rails new Gemfile.

uncomment:

-# gem "image_processing", "~> 1.2"
+gem "image_processing", "~> 1.2"

which updates:
Gemfile.lock

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

However, it was a fairly simple fix based on https://www.libvips.org/install.html since I've used ubuntu a lot to search for a vips package (imagemagick not required)

the Gemfile comment could be changed to:
Please see these dependencies -> https://guides.rubyonrails.org/active_storage_overview.html#requirements

for example for the tutorial i was using the docker ruby image, so I added one new package and rebuilt the container for this:

libvips-dev added below:

FROM ruby:3.1.0-rc-slim

RUN apt-get update -qq
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends
build-essential
gnupg2
curl
less
git
shared-mime-info
libsqlite3-dev
libvips-dev
&& apt-get clean
&& rm -rf /var/cache/apt/archives/*
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
&& truncate -s 0 /var/log/*log

for vips it would be an upstream PR to make the error message better:

The requirement is discussed here. #43182
the error message is coming from ruby-vips
here for heroku libvips/ruby-vips#219

For windows users it looks like the dependency is already installed.
https://github.com/libvips/ruby-vips/pull/211/files

@ghiculescu
Copy link
Member

https://guides.rubyonrails.org/active_storage_overview.html#requirements documents this.

Various features of Active Storage depend on third-party software which Rails will not install, and must be installed separately.

A PR to make the error message better would be awesome, if anyone wants to make one.

@brenogazzola
Copy link
Contributor

If anyone decides to pick that, you can use Analyzer::ImageAnalyzer::Vips as an example. It catches the LoadError and prints a message saying ruby-vips is not installed.

@Zicrou
Copy link

Zicrou commented Jan 24, 2022

If anyone decides to pick that, you can use Analyzer::ImageAnalyzer::Vips as an example. It catches the LoadError and prints a message saying ruby-vips is not installed.

hi can you please tell me where to put that `

Analyzer::ImageAnalyzer::Vips``

`

@charlietag
Copy link

charlietag commented Jan 28, 2022

Root cause

Solution 1 (change back to use ImageMagick like what <= Rails 6 did)

  • config/application.rb

    config.load_defaults 7.0
    + config.active_storage.variant_processor = :mini_magick

Solution 2 (Install libvips v8.6+)

Install via OS package manager

  • Ubuntu

    apt install -y libvips
  • CentOS

    dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
    dnf install -y vips vips-tools

Install by compiling libvips yourself

Notes

libvips is much more faster than ImageMagick

Try to upload image using Rails Action Text

  • Image

    • jpeg 2.5 MB
  • Hardware

    • CPU: 2.34 GHz x1
    • RAM: 1G
  • config.active_storage.variant_processor = :mini_magick
    [ActiveJob] [ActiveStorage::AnalyzeJob] [234839b4-5dbc-49c3-92bf-c8e370c4b295] Performed ActiveStorage::AnalyzeJob (Job ID: 234839b4-5dbc-49c3-92bf-c8e370c4b295) from Async(default) in 101.49ms

  • config.active_storage.variant_processor = :vips (Rails 7 default)
    [ActiveJob] [ActiveStorage::AnalyzeJob] [82417bb7-d637-4a55-adb0-d9c4404734da] Performed ActiveStorage::AnalyzeJob (Job ID: 82417bb7-d637-4a55-adb0-d9c4404734da) from Async(default) in 32.65ms

@rails-bot
Copy link

rails-bot bot commented May 6, 2022

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 7-0-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label May 6, 2022
@rails-bot rails-bot bot closed this as completed May 13, 2022
@charlesdeb
Copy link

Yeah, I had the same issue just now with ActiveStorage. I worked around it by doing apt install -y libvips

@egemen-dev
Copy link

I had a very similar problem when I wanted to view a uploaded picture (using trix) and constantly got this message:

LoadError in ActiveStorage::Representations::RedirectController#show

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

sudo apt install imagemagick libvips fixed the problem.

Thank you for sharing the solution, much appreciated.

@Roald87
Copy link

Roald87 commented Nov 10, 2022

After sudo apt install imagemagick libvips. I got

Liquid Exception: No such file or directory - vips in /home/../
/var/lib/gems/3.0.0/gems/jekyll_picture_tag-2.0.4/lib/jekyll_picture_tag/parsers/image_backend.rb:17:in ``': No such file or directory - vips (Errno::ENOENT)

Then I did sudo apt install libvips-tools and now it finally works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants