'Hugo with asciidoctor broken "can't find gem asciidoctor"
I have an existing blog with Hugo and Asciidoctor, but running hugo server started failing. I first added the additional security configuration as explained in Hugo with Asciidoctor.
But things are still not working, I get this error:
ERROR 2022/02/19 17:11:36 blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: /Users/wdb/.rvm/rubies/ruby-2.7.0/lib/ruby/site_ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': can't find gem asciidoctor (>= 0.a) with executable asciidoctor (Gem::GemNotFoundException)
ERROR 2022/02/19 17:11:36 blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: from /Users/wdb/.rvm/rubies/ruby-2.7.0/lib/ruby/site_ruby/2.7.0/rubygems.rb:296:in `activate_bin_path'
ERROR 2022/02/19 17:11:36 blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: from /Users/wdb/.rvm/gems/ruby-2.7.0/bin/asciidoctor:23:in `<main>'
ERROR 2022/02/19 17:11:36 blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: from /Users/wdb/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
ERROR 2022/02/19 17:11:36 blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: from /Users/wdb/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
ERROR 2022/02/19 17:11:36 asciidoctor rendering blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: failed to execute binary "asciidoctor" with args [--no-header-footer -]: /Users/wdb/.rvm/rubies/ruby-2.7.0/lib/ruby/site_ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': can't find gem asciidoctor (>= 0.a) with executable asciidoctor (Gem::GemNotFoundException)
from /Users/wdb/.rvm/rubies/ruby-2.7.0/lib/ruby/site_ruby/2.7.0/rubygems.rb:296:in `activate_bin_path'
from /Users/wdb/.rvm/gems/ruby-2.7.0/bin/asciidoctor:23:in `<main>'
from /Users/wdb/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /Users/wdb/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
I am using:
- Hugo:
hugo v0.92.0+extended darwin/amd64 BuildDate=unknown - Ruby:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19] - Bundler:
Bundler version 2.1.4
I have a Gemfile like this:
source 'https://rubygems.org'
gem 'asciidoctor'
gem 'rouge'
with Gemfile.lock:
GEM
remote: https://rubygems.org/
specs:
asciidoctor (2.0.17)
rouge (3.28.0)
PLATFORMS
ruby
DEPENDENCIES
asciidoctor
rouge
BUNDLED WITH
2.1.4
Let me know if you need anything else to help me debug this.
UPDATE:
I ran rvm install ruby 2.7.5 to install Ruby 2.7.5 and now I get this error running hugo server:
WARN 2022/02/20 10:47:43 blog/2021/12/23/Taming Thymeleaf 2.0 release.adoc: Ignoring ffi-1.11.3 because its extensions are not built. Try: gem pristine ffi --version 1.11.3
I ran gem install ffi --version='1.11.3' and gem pristine ffi --version 1.11.3, but still the same error message.
Solution 1:[1]
I managed to make it work again by removing RVM completely from my system using the commands in https://rvm.io/support/troubleshooting.
Solution 2:[2]
Actually, this is an expected behavior. Starting from the version 0.91 Hugo filters out the environment for child processes according to some regex. So the issue is simple: GEM_PATH (or GEM_HOME) is filtered out. Read more in this ticket.
To fix it simply whitelist the GEM_PATH variable in your config.yaml (config.toml):
security:
exec:
osEnv:
- (?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM|GEM_PATH)$ # Note this GEM_PATH
allow:
- asciidoctor # Don't forget to whitelist Asciidoctor as well
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wim Deblauwe |
| Solution 2 | madhead |
