Can't setup rails: psych/yaml issue

Hello,

I have been using Rails 7.4.0.3 since its release in March without any issues on a Windows 11 system, having had setup about half a dozen projects since then.

However, an error is now preventing me from creating a new project with the basic “rails new [project]” command. I am getting this lovely feedback instead:

Installing psych 5.1.1.1 with native extensions warning: Public keyring not found; have you run ‘pacman-key --init’? error: mingw32: key “" is unknown error: keyring is not writable error: mingw64: key "” is unknown error: keyring is not writable error: ucrt64: key “" is unknown error: keyring is not writable error: clang32: key "” is unknown error: keyring is not writable error: clang64: key “" is unknown error: keyring is not writable error: msys: key "” is unknown error: keyring is not writable error: database ‘mingw32’ is not valid (invalid or corrupted database (PGP signature)) error: database ‘mingw64’ is not valid (invalid or corrupted database (PGP signature)) error: database ‘ucrt64’ is not valid (invalid or corrupted database (PGP signature)) error: database ‘clang32’ is not valid (invalid or corrupted database (PGP signature)) error: database ‘clang64’ is not valid (invalid or corrupted database (PGP signature)) error: database ‘msys’ is not valid (invalid or corrupted database (PGP signature)) Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: E:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/psych-5.1.1.1/ext/psych E:/Ruby31-x64/bin/ruby.exe -I E:/Ruby31-x64/lib/ruby/3.1.0 extconf.rb checking for yaml.h… no yaml.h not found *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

Provided configuration options: –with-opt-dir –without-opt-dir –with-opt-include –without-opt-include=${opt-dir}/include –with-opt-lib –without-opt-lib=${opt-dir}/lib –with-make-prog –without-make-prog –srcdir=. –curdir –ruby=E:/Ruby31-x64/bin/$(RUBY_BASE_NAME) –with-libyaml-source-dir –without-libyaml-source-dir –with-yaml-0.1-dir –without-yaml-0.1-dir –with-yaml-0.1-include –without-yaml-0.1-include=${yaml-0.1-dir}/include –with-yaml-0.1-lib –without-yaml-0.1-lib=${yaml-0.1-dir}/lib –with-yaml-0.1-config –without-yaml-0.1-config –with-pkg-config –without-pkg-config –with-libyaml-dir –without-libyaml-dir –with-libyaml-include –without-libyaml-include=${libyaml-dir}/include –with-libyaml-lib –without-libyaml-lib=${libyaml-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

E:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/psych-5.1.1.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in E:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/psych-5.1.1.1 for inspection. Results logged to E:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/psych-5.1.1.1/gem_make.out

E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/ext/builder.rb:102:in run' E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:28:in build’ E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/ext/builder.rb:171:in build_extension' E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/ext/builder.rb:205:in block in build_extensions’ E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in each' E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in build_extensions’ E:/Ruby31-x64/lib/ruby/3.1.0/rubygems/installer.rb:843:in build_extensions' E:/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_gem_installer.rb:72:in build_extensions’ E:/Ruby31-x64/lib/ruby/3.1.0/bundler/rubygems_gem_installer.rb:28:in install' E:/Ruby31-x64/lib/ruby/3.1.0/bundler/source/rubygems.rb:207:in install’ E:/Ruby31-x64/lib/ruby/3.1.0/bundler/installer/gem_installer.rb:54:in install' E:/Ruby31-x64/lib/ruby/3.1.0/bundler/installer/gem_installer.rb:16:in install_from_spec’ E:/Ruby31-x64/lib/ruby/3.1.0/bundler/installer/parallel_installer.rb:186:in do_install' E:/Ruby31-x64/lib/ruby/3.1.0/bundler/installer/parallel_installer.rb:177:in block in worker_pool’ E:/Ruby31-x64/lib/ruby/3.1.0/bundler/worker.rb:62:in apply_func' E:/Ruby31-x64/lib/ruby/3.1.0/bundler/worker.rb:57:in block in process_queue’ E:/Ruby31-x64/lib/ruby/3.1.0/bundler/worker.rb:54:in loop' E:/Ruby31-x64/lib/ruby/3.1.0/bundler/worker.rb:54:in process_queue’ E:/Ruby31-x64/lib/ruby/3.1.0/bundler/worker.rb:91:in `block (2 levels) in create_threads’

An error occurred while installing psych (5.1.1.1), and Bundler cannot continue.

In Gemfile: debug was resolved to 1.8.0, which depends on irb was resolved to 1.8.3, which depends on rdoc was resolved to 6.5.0, which depends on psych run bundle lock --add-platform=x86_64-linux Writing lockfile to E:/Projets/stuff/Gemfile.lock run bundle binstubs bundler Could not find turbo-rails-1.5.0, stimulus-rails-1.3.0, web-console-4.2.1, irb-1.8.3, rdoc-6.5.0, psych-5.1.1.1 in locally installed gems rails importmap:install Could not find turbo-rails-1.5.0, stimulus-rails-1.3.0, web-console-4.2.1, irb-1.8.3, rdoc-6.5.0, psych-5.1.1.1 in locally installed gems Run bundle install to install missing gems. rails turbo:install stimulus:install Could not find turbo-rails-1.5.0, stimulus-rails-1.3.0, web-console-4.2.1, irb-1.8.3, rdoc-6.5.0, psych-5.1.1.1 in locally installed gems Run bundle install to install missing gems.

I’m at a loss. Why is this happening? Why now? I can tell that yaml.h is missing from the log file referred to in the error message:

conftest.c:5:10: fatal error: yaml.h: No such file or directory 5 | #include <yaml.h> | ^~~~~~~~ compilation terminated. checked program was: /* begin / 1: #include “ruby.h” 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: #include <yaml.h> / end */

I configured a custom Rake task for the first time yesterday and it worked fine - this is the only part of my work that stood out as unusual, so you can tell I’ve been sticking to really basic stuff. I could understand how dependencies can go out of date but I’m puzzled as to why this one seemed to have disappeared entirely. I created a new project last week without a hitch. Googling about yaml.h gives me a bunch of 10 year old tickets for Python related issues and installation tips for Ubuntu, which are completely useless to me. At this point I figure I might as well try installing a more recent version of Rails but that without understanding why the problem showed up in the first place, I don’t really see the point. So what’s wrong?

EDIT: Looks like I am actually getting the mistake when installing a Rails 7.1.1 project.

1 Like

I encounted same error on Rails 7.1.1.

to fix psych’s installation, i exec brew install libyaml and bundle install

1 Like

Thank you for the hints. I used “gem install yaml” and “bundle install” and although I am still getting the keyring errors on psych when setuping the project, everything seems to work fine once I run bundle install. I also installed the version of Rails I’d been previously using “rails 7.0.4.3 new [project]”, so maybe that helped too.

For ubuntu, apt-get install libyaml-dev works

2 Likes

I’m having this same problem on windows 11 with a clean install of ruby.

Has anyone here managed to fix this issue? I’m having the same issues on Windows 11 :(.

Did you try using gem install yaml? I don’t think I ever found out what the exact issue was, but it never reappeared once I ran that + bundle install. I also used a previous version of Rails but I’m fairly sure this wasn’t part of the solution, as my projects using the newer versions work fine. This leads me to believe that this yaml thing being mis-installed or mis-configured somehow was at the root of the issue. I’d suggest fiddling around with installing/re-installing it. Wish I had better/more specific advice to give but it seems like there was a bit of black magic at work here. Hopefully someone with a better grasp of the issue can come in and save the day.

Hey there, I am running to similar issues as you have had. I am following the rails guide and ran gem install yaml then bundle install but it is not working.

This problem occurs because the system dependencies are not satisfied, if you’re using alpine linux installing the yaml-dev package will solve the problem.

apk add yaml-dev

Something’s deeply wonky with this issue. I had used https://www.msys2.org/ to download/install the libyaml package, which seemed to have did it for a while. Then I started running into this issue again. Libyaml is still installed…

My solution (for now) is to use the Gemfile to force a previous version of psych: gem 'psych', '4.0.0'. This works fine, but I still don’t understand why this is issue keeps recurring or why it can’t find libyaml, even after adjusting the PATH to the library’s location.

i encountered the same problem with rouby on rails 7.1.1 and i first did gem install psych then i ran bundle install which solved the problem however i dont know if i will be doing this in every application i create

1 Like
brew info libyaml
brew list libyaml
gem install psych -- --with-libyaml-dir=/opt/homebrew/Cellar/libyaml/0.2.5
  • don’t forget to update the libyaml path

Thanks! From within the rails project, running gem install psych and then bundle install solved this error for me. (Windows 11, Rails 7.1.3, Ruby 3.2.3)

Open an admin powershell and run “gem install rails”

Sorry my english not good.

I am using windows 10:

you must to do :

  1. MSYS2 UCRT64 Shell (C:\msys64\ucrt64.exe) $ pacman-key --init $ $ gpg --import archlinux-keyring.gpg

  2. bundle in GitBash $ bundle

    –success–

I prepared a short video about these issues (For Windows)