libffi.so.7: cannot open shared object file: No such file or directory

I just upgraded to ubuntu 20.10 and when I tried to work with rails app that was working perfectly fine earlier started to show this error.

LoadError: libffi.so.7: cannot open shared object file: No such file or directory - 
/home/mahmud/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ffi-1.13.1/lib/ffi_c.so

My rails version:6.0.3.4 Ruby Version: 2.7.1p83 I installed ruby using rbenv Can any one tell me what I have messed up?


Solution 1:

Ubuntu 20.04 came with a shared library called libffi.so.7, from the package libffi7. This library has been referenced by one of your ruby gems, ffi.

In the standard repos for Ubuntu 20.10 there's no package libffi7 anymore, so it has probably been removed from your system during the upgrade. Instead, Ubuntu 20.10 brings a package named libffi8ubuntu1.

You'll need at least to check whether the libffi8ubuntu1 package is installed and reinstall the ffi gem, so it references libffi8 instead of libff7. I don't know whether libffi8 just replaces libffi7 in your use case, or whether you need to make more changes. Possibly you need to wait until the developers up the chain (the developer of the ffi gem and so forth) have made any neccessary adjustments and then install the new versions.

Solution 2:

Since Ubuntu 20.10 comes with libff8 instead of libffi7, I installed libffi7 by manually downloading the deb package from ubuntu focal (20.04):

wget http://es.archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi7_3.3-4_amd64.deb
sudo dpkg -i libffi7_3.3-4_amd64.deb

After that I could successfully install the ffi gem.

This didn't require installing or changing any other packages. Also, the default libffi shared library seems to be libffi8:

$ ldconfig -p |  grep ffi
    libffi.so.8 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libffi.so.8
    libffi.so.8 (libc6) => /usr/lib/i386-linux-gnu/libffi.so.8
    libffi.so.7 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libffi.so.7
    libffi.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libffi.so
$ ls -l /usr/lib/x86_64-linux-gnu/libffi.so
lrwxrwxrwx 1 root root 15 ago 20 11:31 /usr/lib/x86_64-linux-gnu/libffi.so -> libffi.so.8.1.0

So far I haven't experienced any issues.

Solution 3:

The answer by Henning Kockerbeck explains why it doesn't work - the newer Ubuntu version no longer provides the same shared system package BUT the gem was installed before the upgrade and still points to the old shared package.

Now, my fix may not work for you because I'm using rvm and not rbenv, but I think it might lead you down a useful route. I reinstalled the ruby version (for rvm this pretty much removes all the gems associated with that version and reinstalls them - this time pointing to the correct shared package).

rvm reinstall --disable-binary 2.5.7

The equivalent for rbenv might be:
rbenv uninstall 1.9.3-p0

rbenv install 1.9.3-p0