Cannot create new rails app - error while install gem ffi

When I type ‘rails new myapp’ i get error ''An error occurred while installing ffi (1.15.4), and Bundler cannot continue."

my specs:

os: Mageia 8 64bit
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
Rails 6.1.4.1
Yarn 1.22.10
Node v14.16.0

Error Code

[maciek@DESKTOP-EGREOTM Documents]$ rails new railsapp
      create  
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  .gitattributes
      create  Gemfile
         run  git init from "."
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /home/maciek/Documents/railsapp/.git/
      create  package.json
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/javascript/channels/consumer.js
      create  app/javascript/channels/index.js
      create  app/javascript/packs/application.js
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/spring
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/spring.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_6_1.rb
      create  config/initializers/permissions_policy.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/pids
      create  tmp/pids/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/channels/application_cable/connection_test.rb
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_6_1.rb
         run  bundle install
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies......
Using rake 13.0.6
Following files may not be writable, so sudo is needed:
  /usr/bin
  /usr/share/gems
  /usr/share/gems/build_info
  /usr/share/gems/build_info/ffi-1.12.2.info
  /usr/share/gems/cache
  /usr/share/gems/doc
  /usr/share/gems/extensions
  /usr/share/gems/gems
  /usr/share/gems/specifications
Using racc 1.6.0
Using marcel 1.0.2
Using bindex 0.8.1
Using nio4r 2.5.8
Using bundler 2.2.31
Using concurrent-ruby 1.1.9
Using minitest 5.14.4
Using zeitwerk 2.5.1
Using builder 3.2.4
Using erubi 1.10.0
Using mini_mime 1.1.2
Using crass 1.0.6
Fetching ffi 1.15.4
Using rack 2.2.3
Using msgpack 1.4.2
Using websocket-extensions 0.1.5
Using byebug 11.1.3
Using matrix 0.4.2
Using regexp_parser 2.1.1
Using childprocess 4.1.0
Using rb-fsevent 0.11.0
Using method_source 1.0.0
Using public_suffix 4.0.6
Using thor 1.1.0
Using rexml 3.2.5
Using i18n 1.8.11
Using mail 2.7.1
Using rack-test 1.1.0
Using rack-mini-profiler 2.3.3
Using sqlite3 1.4.2
Using sprockets 4.0.2
Using bootsnap 1.9.1
Using puma 5.5.2
Using tzinfo 2.0.4
Using rubyzip 2.3.2
Using activesupport 6.1.4.1
Using selenium-webdriver 4.0.3
Using globalid 0.5.2
Using activemodel 6.1.4.1
Using activejob 6.1.4.1
Using activerecord 6.1.4.1
Using websocket-driver 0.7.5
Using addressable 2.8.0
Using tilt 2.0.10
Using semantic_range 3.0.0
Using spring 3.0.0
Using jbuilder 2.11.3
Using rack-proxy 0.7.0
Using turbolinks-source 5.2.0
Using nokogiri 1.12.5 (x86_64-linux)
Using turbolinks 5.2.1
Using rails-dom-testing 2.0.3
Using xpath 3.2.0
Using webdrivers 5.0.0
Using capybara 3.36.0
Using loofah 2.12.0
Using rails-html-sanitizer 1.4.2
Using actionview 6.1.4.1
Using actionpack 6.1.4.1
Using actioncable 6.1.4.1
Using activestorage 6.1.4.1
Using actionmailer 6.1.4.1
Using actiontext 6.1.4.1
Using sprockets-rails 3.4.0
Using railties 6.1.4.1
Using actionmailbox 6.1.4.1
Using webpacker 5.4.3
Using rails 6.1.4.1
Using web-console 4.1.0


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle config set --local path 'vendor/bundle'
      bundle install

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle config set --local path 'vendor/bundle'
      bundle install

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 
Installing ffi 1.15.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c
/usr/bin/ruby -I /usr/share/rubygems -r ./siteconf20211117-52075-1x5pa56.rb extconf.rb
checking for ffi_prep_closure_loc() in -lffi... yes
checking for ffi_prep_cif_var()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for whether -pthread is accepted as LDFLAGS... yes
creating extconf.h
creating Makefile

current directory: /tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c
make "DESTDIR=" clean
rm -f 
rm -f ffi_c.so  *.o  *.bak mkmf.log .*.time

current directory: /tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c
make "DESTDIR="
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o AbstractMemory.o -c
AbstractMemory.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o ArrayType.o -c ArrayType.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Buffer.o -c Buffer.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Call.o -c Call.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o ClosurePool.o -c
ClosurePool.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o DynamicLibrary.o -c
DynamicLibrary.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Function.o -c Function.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o FunctionInfo.o -c
FunctionInfo.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o LastError.o -c LastError.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o LongDouble.o -c
LongDouble.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o MappedType.o -c
MappedType.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o MemoryPointer.o -c
MemoryPointer.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o MethodHandle.o -c
MethodHandle.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Platform.o -c Platform.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Pointer.o -c Pointer.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Struct.o -c Struct.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o StructByValue.o -c
StructByValue.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o StructLayout.o -c
StructLayout.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Thread.o -c Thread.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Type.o -c Type.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Types.o -c Types.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o Variadic.o -c Variadic.c
x86_64-mageia-linux-gnu-gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. 
-DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -fPIC   -o ffi.o -c ffi.c
rm -f ffi_c.so
x86_64-mageia-linux-gnu-gcc -shared -o ffi_c.so AbstractMemory.o ArrayType.o Buffer.o Call.o ClosurePool.o
DynamicLibrary.o Function.o FunctionInfo.o LastError.o LongDouble.o MappedType.o MemoryPointer.o
MethodHandle.o Platform.o Pointer.o Struct.o StructByValue.o StructLayout.o Thread.o Type.o Types.o Variadic.o
ffi.o -L. -L/usr/lib64 -L.  -Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro -Wl,-O1 -Wl,--build-id
-Wl,--enable-new-dtags -fstack-protector-strong -rdynamic -Wl,-export-dynamic  -pthread -Wl,--as-needed
-Wl,--no-undefined -Wl,-z,relro -Wl,-O1 -Wl,--build-id -Wl,--enable-new-dtags    -lruby -lffi  -lffi -lm   -lc
/usr/bin/ld: DynamicLibrary.o: in function `library_dlsym':
/tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c/DynamicLibrary.c:148: undefined
reference to `dlsym'
/usr/bin/ld: DynamicLibrary.o: in function `library_dlerror':
/tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c/DynamicLibrary.c:161: undefined
reference to `dlerror'
/usr/bin/ld: DynamicLibrary.o: in function `library_initialize':
/tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c/DynamicLibrary.c:119: undefined
reference to `dlopen'
/usr/bin/ld: /tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c/DynamicLibrary.c:122:
undefined reference to `dlerror'
/usr/bin/ld: DynamicLibrary.o: in function `library_free':
/tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4/ext/ffi_c/DynamicLibrary.c:171: undefined
reference to `dlclose'
collect2: error: ld returned 1 exit status
make: *** [Makefile:263: ffi_c.so] Error 1

make failed, exit code 2

Gem files will remain installed in /tmp/bundler20211117-52075-4e3xsnffi-1.15.4/gems/ffi-1.15.4 for inspection.
Results logged to
/tmp/bundler20211117-52075-4e3xsnffi-1.15.4/extensions/x86_64-linux/2.7.0/ffi-1.15.4/gem_make.out

  /usr/share/rubygems/rubygems/ext/builder.rb:99:in `run'
  /usr/share/rubygems/rubygems/ext/builder.rb:51:in `block in make'
  /usr/share/rubygems/rubygems/ext/builder.rb:43:in `each'
  /usr/share/rubygems/rubygems/ext/builder.rb:43:in `make'
  /usr/share/rubygems/rubygems/ext/ext_conf_builder.rb:63:in `block in build'
  /usr/share/ruby/tempfile.rb:291:in `open'
  /usr/share/rubygems/rubygems/ext/ext_conf_builder.rb:30:in `build'
  /usr/share/rubygems/rubygems/ext/builder.rb:169:in `block in build_extension'
  /usr/share/rubygems/rubygems/ext/builder.rb:165:in `synchronize'
  /usr/share/rubygems/rubygems/ext/builder.rb:165:in `build_extension'
  /usr/share/rubygems/rubygems/ext/builder.rb:210:in `block in build_extensions'
  /usr/share/rubygems/rubygems/ext/builder.rb:207:in `each'
  /usr/share/rubygems/rubygems/ext/builder.rb:207:in `build_extensions'
  /usr/share/rubygems/rubygems/installer.rb:844:in `build_extensions'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/rubygems_gem_installer.rb:71:in `build_extensions'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/source/rubygems.rb:200:in `install'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/installer/gem_installer.rb:54:in `install'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/installer/parallel_installer.rb:186:in `do_install'
/home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/installer/parallel_installer.rb:177:in `block in
worker_pool'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/worker.rb:62:in `apply_func'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/worker.rb:57:in `block in process_queue'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/worker.rb:54:in `loop'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/worker.rb:54:in `process_queue'
  /home/maciek/.gem/ruby/gems/bundler-2.2.31/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads'

An error occurred while installing ffi (1.15.4), and Bundler cannot continue.

In Gemfile:
  listen was resolved to 3.7.0, which depends on
    rb-inotify was resolved to 0.10.1, which depends on
      ffi
         run  bundle binstubs bundler
Could not find gem 'sass-rails (>= 6)' in locally installed gems.
       rails  webpacker:install
Could not find gem 'sass-rails (>= 6)' in locally installed gems.

I searched the net for “ffi undefined reference to `dlsym’” and I found c++ - Undefined reference to 'dlsym' - Stack Overflow. I suspect you either need to use a different compiler or you will need to set some compilation flags in your environment.

This has helped me in the past, but doesn’t always work. Has been a continuing problem for me using chruby on macOS. gem install ffi -v '1.15.3' -- --with-cflags="-Wno-error=implicit-function-declaration". Obviously match version needed. Here’s a link on SO that must have helped me.

Some of the things I’ve tried based on SO posts on this and similar problems

Removed Gemfile.lock and still bundle install failed

Tried ruby-install ruby 2.7.0 just in case. I’m using chruby and still bundle install failed

sudo xcodebuild -license and still bundle install failed

Tried commenting out source github and still bundle install failed

Tried gem install ffi and still bundle install failed share any suggestions.