Can't use Nokogiri gem on M1 processor - ruby-on-rails

I have a problem with using the M1 processor and Nokogiri gem.
Gemfile
...
gem 'nokogiri', '>= 1.13.5'
...
When I run bundle install, all seems good, but when I try to run specs, for example, I see the error:
LoadError:
dlopen(/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle, 0x0009): tried: '/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) - /Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6/lib/nokogiri/nokogiri.bundle
I've tried to install Nokogiri with gem install nokogiri -v 1.13.6 --platform arm64-darwin, and now it looks like that:
nokogiri -versions:
# Nokogiri (1.13.6)
---
warnings: []
nokogiri:
version: 1.13.6
cppflags:
- "-I/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri"
- "-I/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri/include"
- "-I/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri/include/libxml2"
ldflags: []
ruby:
version: 2.7.2
platform: arm64-darwin21
gem_platform: arm64-darwin-21
description: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin21]
engine: ruby
libxml:
source: packaged
precompiled: true
patches:
- 0001-Remove-script-macro-support.patch
- 0002-Update-entities-to-remove-handling-of-ssi.patch
- 0003-libxml2.la-is-in-top_builddir.patch
- 0004-use-glibc-strlen.patch
- 0005-avoid-isnan-isinf.patch
- 0006-update-automake-files-for-arm64.patch
- '0008-htmlParseComment-handle-abruptly-closed-comments.patch'
- '0009-allow-wildcard-namespaces.patch'
libxml2_path: "/Users/ruslan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/nokogiri-1.13.6-arm64-darwin/ext/nokogiri"
memory_management: ruby
iconv_enabled: true
compiled: 2.9.14
loaded: 2.9.14
libxslt:
source: packaged
precompiled: true
patches:
- 0001-update-automake-files-for-arm64.patch
datetime_enabled: true
compiled: 1.1.35
loaded: 1.1.35
other_libraries:
zlib: 1.2.12
libiconv: '1.16'
libgumbo: 1.0.0-nokogiri
But when I try to run specs with this version only, I have an error:
Could not find nokogiri-1.13.6 in any of the sources
Run `bundle install` to install missing gems.
So to avoid this error, I have to install Nokogiri through bundle install, but it installs the wrong version, not for the arm platform, and then I have a problem with the platform. If I install Nokogiri through the gem install command, the bundler doesn't see it.
My bundle config:
Settings are listed in order of priority. The top value will be used.
build.libv8
Set for the current user (/Users/ruslan/.bundle/config): "--with-system-v8"
build.libxml-ruby
Set for the current user (/Users/ruslan/.bundle/config): "--with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config"
build.nokogiri
Set for your local app (/Users/ruslan/3commas/3commas/.bundle/config): "--use-system-libraries"
default
Set for the current user (/Users/ruslan/.bundle/config): "2.2.21"
force_ruby_platform
Set for your local app (/Users/ruslan/3commas/3commas/.bundle/config): true
Set for the current user (/Users/ruslan/.bundle/config): true
github.https
Set for the current user (/Users/ruslan/.bundle/config): "true"
Maybe somebody knows how to figure out this problem? Many thanks in advance! 🙏

I wonder if this is an issue related to the Gemfile.lock file, which can have explicit platforms to bundle for. You can check by looking for PLATFORMS within that file.
If you add Apple's ARM platform to your setup via bundler, that may help the correct version of nokogiri to be bundled? Try running the following on the command line:
bundle lock --add-platform arm64-darwin-21

Related

can't find gem jekyll (>= 0.a) with executable jekyll (Gem::GemNotFoundException)

The bounty expires tomorrow. Answers to this question are eligible for a +100 reputation bounty.
Kadaj13 wants to draw more attention to this question.
I am trying to make my personal website using github and jekyll following the instructions on the official website
When I reach the part:
jekyll new --skip-bundle
I received:
can't find gem jekyll (>= 0.a) with executable jekyll (Gem::GemNotFoundException)
I tried several approaches, such as the one mentioned here and I ran the command with sudo. Again after running jekyll new --skip-bundle .
Here is the terminal response after installing with instructions here
Fetching bundler-2.4.5.gem
Successfully installed bundler-2.4.5
Parsing documentation for bundler-2.4.5
Installing ri documentation for bundler-2.4.5
Done installing documentation for bundler after 0 seconds
1 gem installed
And here is the terminal response when I run jekyll new --skip-bundle again:
Traceback (most recent call last):
2: from /usr/local/bin/jekyll:22:in `<main>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:262:in `bin_path'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem jekyll (>= 0.a) with executable jekyll (Gem::GemNotFoundException)
I appreciate if you can help me how to solve it.
I use macOs.
Update:
I run bundle add jekyll and I received:
Your RubyGems version (3.0.3) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3
Could not locate Gemfile`
Then I run gem update --system 3.2.3
Updating rubygems-update
Fetching rubygems-update-3.2.3.gem
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
Next step I run sudo gem update --system 3.2.3 and I received:
Updating rubygems-update
Fetching rubygems-update-3.2.3.gem
Successfully installed rubygems-update-3.2.3
Parsing documentation for rubygems-update-3.2.3
Installing ri documentation for rubygems-update-3.2.3
Installing darkfish documentation for rubygems-update-3.2.3
Done installing documentation for rubygems-update after 78 seconds
Parsing documentation for rubygems-update-3.2.3
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.2.3
ERROR: While executing gem ... (Errno::EROFS)
Read-only file system # rb_sysopen - /usr/share/man/man1/bundle-platform.1
So still I failed to add jekyll....
System information:
Ruby: ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
Gem: 3.2.3
Bundler: version 2.4.6
Homebrew:
Homebrew 3.6.20
Homebrew/homebrew-core (git revision fc36a19edf4; last commit 2023-02-04)
Homebrew/homebrew-cask (git revision 4c5d3e2391; last commit 2023-02-04)
CPU: Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
Update 2:
Should I run these commands where my gem files are located?
I run gem environment and here is what I received. In which directory should I run these commands?
RubyGems Environment:
- RUBYGEMS VERSION: 3.2.3
- RUBY VERSION: 2.6.3 (2019-04-16 patchlevel 62) [universal.x86_64-darwin19]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/shirinvafaei/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
- GIT EXECUTABLE: /usr/local/bin/git
- EXECUTABLE DIRECTORY: /usr/bin
- SPEC CACHE DIRECTORY: /Users/shirinvafaei/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-19
- GEM PATHS:
- /Library/Ruby/Gems/2.6.0
- /Users/shirinvafaei/.gem/ruby/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/shirinvafaei/.rbenv/shims
- /Users/shirinvafaei/.rbenv/bin
- /usr/local/Cellar/ruby/2.4.1_1/bin
- /usr/local/bin
- /Users/shirinvafaei/opt/anaconda3/bin
- /Users/shirinvafaei/opt/anaconda3/condabin
- /Library/Frameworks/Python.framework/Versions/2.7/bin
- /Library/Frameworks/Python.framework/Versions/3.8/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /opt/X11/bin
Another update:
I tried
rben install 3.0.5
and I received this error message:
eb322180c6f18a6f74e4b6aa
Installing openssl-1.1.1s...
BUILD FAILED (Mac OS X 10.15.7 using ruby-build 20230202)
Inspect or clean up the working tree at /var/folders/yk/clm8vmf15r9cv4hghy2wm6380000gn/T/ruby-build.20230215141911.2345.jn3ObC
Results logged to /var/folders/yk/clm8vmf15r9cv4hghy2wm6380000gn/T/ruby-build.20230215141911.2345.log
Last 10 log lines:
_dgram_write in bss_dgram.o
_fd_write in bss_fd.o
_fd_puts in bss_fd.o
_sock_write in bss_sock.o
_sock_puts in bss_sock.o
(maybe you meant: _UI_method_get_writer, _RAND_write_file , _PEM_write_bio_PKCS7_stream , _PEM_write_X509_AUX , _PEM_write_PrivateKey , _PEM_write_bio_PrivateKey_traditional , _PEM_write_bio_PrivateKey , _PEM_write_PKCS8_PRIV_KEY_INFO , _PEM_write_bio_PKCS8_PRIV_KEY_INFO , _PEM_write_PKCS8PrivateKey , _PEM_write_bio_PKCS8PrivateKey , _PEM_write_bio , _PEM_X509_INFO_write_bio , _PEM_write_bio_PUBKEY , _PEM_write_DHparams , _PEM_write_EC_PUBKEY , _PEM_write_bio_EC_PUBKEY , _PEM_write_bio_ECPKParameters , _PEM_write_DSA_PUBKEY , _PEM_write_bio_RSA_PUBKEY , _PEM_write_RSAPublicKey , _PEM_write_PKCS7 , _PEM_write_bio_PKCS7 , _PEM_write_X509_CRL , _PEM_write_bio_X509_REQ_NEW , _PEM_write_X509_REQ , _PEM_write_bio_X509 , _PEM_write_PKCS8 , _PEM_write_DHxparams , _PEM_write_DSAparams , _PEM_write_ECPKParameters , _PEM_write_bio_RSAPrivateKey , _UI_method_set_writer , _PEM_write_bio_X509_AUX , _PEM_write_ECPrivateKey , _SMIME_write_CMS , _PEM_write_DSAPrivateKey , _PEM_write_X509 , _PEM_write , _PEM_write_bio_DSAPrivateKey , _PEM_write_bio_X509_CRL , _PEM_write_bio_NETSCAPE_CERT_SEQUENCE , _SMIME_write_PKCS7 , _PEM_ASN1_write , _PEM_ASN1_write_bio , _PEM_write_bio_CMS , _CRYPTO_THREAD_write_lock , _PEM_write_bio_DHxparams , _PEM_write_bio_DSAparams , _PEM_write_RSA_PUBKEY , _TXT_DB_write , _PEM_write_PUBKEY , _BIO_meth_set_write_ex , _BIO_meth_set_write , _BIO_meth_get_write , _PEM_write_bio_DSA_PUBKEY , _BIO_write_ex , _PEM_write_bio_X509_REQ , _PEM_write_bio_Parameters , _PEM_write_bio_ECPrivateKey , _PEM_write_bio_PKCS8 , _PEM_write_X509_REQ_NEW , _PEM_write_bio_DHparams , _BIO_ctrl_get_write_guarantee , _BIO_meth_get_write_ex , _PEM_write_bio_PKCS8PrivateKey_nid , _PEM_write_bio_ASN1_stream , _PEM_write_bio_CMS_stream , _BIO_write , _PEM_write_CMS , _PEM_write_RSAPrivateKey , _PEM_write_NETSCAPE_CERT_SEQUENCE , _PEM_write_PKCS8PrivateKey_nid , _SMIME_write_ASN1 , _PEM_write_bio_RSAPublicKey )
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libcrypto.dylib] Error 1
make: *** [all] Error 2
Do you know how can I fix this one?
Here is the terminal response after installing with instructions here
You are running this to install Bundler (You can think about it as the gem storage). And here you know that for the jekyll error code, it has the same issue (it is not finding the source to run jekyll). To fix this, install jekyll
If you want to run the jekyll from bundler, try this (recommended) Reference
bundle add jekyll #This will add jekyll to Gemfile (gem dependencies manager)
bundle install #This will check/install the gem from Gemfile
bundle exec jekyll #This will run jekyll from the bundle
If you don't want to use bundle, you can install the gem directly
gem install jekyll
jekyll #this should work and have message related to jekyll
Edit after update 1: (and posted reply to further debug things)
Basically, if you can do these (manual thing of the commands above)
Have Gemfile with gem "jekyll" line inside
can run bundle install and success, then you can proceed with the other jekyll related things.
Ruby 2.6 is the 2018 version and has reached end of life
I'd start by upgrading ruby to 3.0 or 3.1 (a lot of gems may not be compatible with 3.2 yet)
Read-only file system # rb_sysopen
Permission issue perhaps? Check if the directory is read only or root access only.
rbenv is a tool for managing ruby versions. You could consider installing ruby through rbenv instead of a plain system install. Would probably solve the permission problem as well.
I see several problems with your setup.
You are using an EOL version of Ruby that is no longer supported.
You are using a system installed ruby which requires root permissions to manage. Apart from security considerations, this creates further issues in gem maintenance.
Because you are forced to run gem install as superuser I don't think that the jekyll binary is set up correctly in the correct path. I think what may have happened is that paths or binaries were setup for the root user instead of your user, as a side effect of running with sudo.
What I recommend is installing a userspace Ruby version manager. My preferred is rbenv because if it's simplicity of operation, but there are others like RVM.
What this entails is:
Installing rbenv (it's quite simple - just follow their README).
Install a recent Ruby version that jekyll supports, like 3.0.5 via:
rbenv install 3.0.5
Run bundle install or gem install jekyll.
rbenv will setup your Ruby environment in userspace where sudo will not be required. All binaries should be correctly accessible in your path and your setup should now be working correctly.
P.S. You may have to restart your terminal session after installing rbenv and after installing the required Ruby version.

Error installing nokogumbo gem with specific version

I am trying to do bundle install on my project.
Ruby: 2.5.1
Rails: 5.0.7.2
Bundler: 1.17.3
But when doing the bundle install, it gives me this error with the nokogumbo gem and it doesn't install it, I'm using a mac.enter image description here
Have you tried:
bundle config set force_ruby_platform true
bundle install
Otherwise, paste in your commands and the output so we can see a better view of what is going on.

Redmine requires bundler 1.5.0 or higher

I am trying to set up RedMine on Ubuntu 14.04.5 LTS machine and in the end of install have following error:
Redmine requires Bundler 1.5.0 or higher (you're using 1.3.5).
Please update with 'gem update bundler'. (SystemExit)
However, gem update bundlergives me following:
gem update bundler
Updating installed gems
Nothing to update
Moreover:
$ bundle -v
Bundler version 1.15.3
$ gem list | grep bundler
bundler (1.15.3)
I am totally stuck.
Could anybody tell me how to fix it?
I've tried to remove Bundler version check in Gemfile. Then I have following error:
`x64_mingw` is not a valid platform. The available options are: [:ruby, :ruby_18, :ruby_19, :ruby_20, :mri, :mri_18, :mri_19, :mri_20, :rbx, :jruby, :mswin, :mingw, :mingw_18, :mingw_19, :mingw_20] (Bundler::GemfileError)
I've checked solutions here: http://www.redmine.org/issues/19409 and here http://www.redmine.org/issues/19469 - nothing helps...
After this steps: Redmine installation : Error
I have cannot load such file -- bundler/setup (LoadError) error. But bundler is installed and still have version 1.15.3
Please help. I am totally disappointed with these errors.
Sorry for my english.
Try
bundle clean
to remove all bundled gems
Then
bundle install
to install required gems
Edit:
After seeing your new error, look at this answer:
'x64_mingw' is not a valid platform
And this RedMine board post:
http://www.redmine.org/boards/2/topics/45759
An updated bundler gem should be ok, but also check your Gemfile and remove any reference to x64_mingw before running bundle install

Installe RMagick gem locally but unable to do the same using bundle install [windows 7(32 bit)]

I was able to install the rmagick-2.6.0-x86-mswin32.gem gem in my windows 7 machine using gem install command and I got the following success messages:
D:\dev>gem install rmagick-2.6.0
Successfully installed rmagick-2.6.0-x86-mswin32
1 gem installed
Installing ri documentation for rmagick-2.6.0-x86-mswin32...
Installing RDoc documentation for rmagick-2.6.0-x86-mswin32...
But when I try to install using bundle install (with the same version mentioned in the Gemfile) it throws the following error messages:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
. D:/Ruby187/bin/ruby.exe extconf.rb
checking for Ruby version >= 1.8.2... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.6.0. Can't find Magick-config in D:\Ruby187\bin;D:\Ruby1
....
I already have ImageMagick installed and its paths included in the env vars, but the paths mentioned in the error message above seem to be different somehow(?!)
When i type rails -v now, I get the following message:
D:\dev>rails -v
←[31mCould not find gem 'rmagick (= 2.6.0) x86-mingw32' in the gems available on
this machine.←[0m
←[33mRun `bundle install` to install missing gems.←[0m
Do i need to make any other changes/ setups to install this gem with my gemfile using bundle install?
Also I actually need an earlier gem '2.5.2' but the win32 specific version of that gem does not seem to available, is there any way to get it?
I need to do this development on windows for the moment so I can switch to any other OS for the moment. Also since this is a legacy app I am working on, I will need to stick with rmagick and can't switch to any other solution.
Env info:
Ruby: 1.8.7
Rails:
Please help!
Many thanks.
Hey have you tried installing Devkit, for installing gems with native extensions on windows.
Try the steps in the following link, and check whether the Devkit has been installed in your path variable, try opening a new command shell and install the gems.
http://doelsengupta.blogspot.in/2010/10/unable-to-download-gem-with-native.html
all the best!!
I kept having this problem but was finally able to get around it using the following solution from #Martin Cohen - after modifying the gemspec file as he has suggested and rebuilding it, i was able to successfully install rmagick gem using bundle install...
https://stackoverflow.com/a/5595274/1865578
cheers!

can't find gem rails - Gem::GemNotFoundException

Using ubuntu 10.04, rvm. At first, I've installed ruby 1.9.2 with rvm, gem rails and generated some new project and started it successfully. Everything was working fine. But after changing to another project, executing bundle install command (output looks OK) and starting rails server - error occurs:
rails s
/home/jacek/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/site_ruby/1.9.1/rubygems.rb:316:in `bin_path': can't find gem rails ([">= 0"]) with executable rails (Gem::GemNotFoundException)
from /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin/rails:19:in `<main>'
gem list rails
*** LOCAL GEMS ***
rails (3.2.2)
gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.18
- RUBY VERSION: 1.9.2 (2012-02-14 patchlevel 318) [i686-linux]
- INSTALLATION DIRECTORY: /home/jacek/.rvm/gems/ruby-1.9.2-p318
- RUBY EXECUTABLE: /home/jacek/.rvm/rubies/ruby-1.9.2-p318/bin/ruby
- EXECUTABLE DIRECTORY: /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/jacek/.rvm/gems/ruby-1.9.2-p318
- /home/jacek/.rvm/gems/ruby-1.9.2-p318#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
My Path (includes EXECUTABLE DIRECTORY: /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin )
/home/jacek/.rvm/gems/ruby-1.9.2-p318/bin:/home/jacek/.rvm/gems/ruby-1.9.2-p318#global/bin:/home/jacek/.rvm/rubies/ruby-1.9.2-p318/bin:/home/jacek/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I would be grateful for any help
For me just installed bundler. This makes everything work again.
gem install bundler --no-ri --no-rdoc
If you use the command bundle install to install your gems off of a GEMFILE, it will install the gems into your default system location for gems, as outlined in the bundler docs here. After that, you can use bundlers bundle exec command to execute a command in the context of the bundle, as outlined in the docs here. This will ensure that the version of the gem you installed using bundle install is executed.
If you look at the homepage for bundler, which provides an overview of the docs, it states the following:
In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.
However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.
I'm guessing that you run gem which rails in your console, and then run bundle show rails in your console, the default installed rails installation for your system differs from the one installed for your bundle.
You say that you are using rvm for your ruby and gem management. I'm thinking you may not have properly configured it. Trying executing the rvm notes command in your console to ensure that you have addressed all of the required/recommended steps for installation on your OS. You want to ensure that the executables for rvm are the first things included in your path when you run echo $PATH ideally. This will ensure that the gems installed for rvm will be the ones executed when you try executing them without prefixing bundle exec. If rvm notes doesn't give you the hints necessary to accomplish that, then try carefully reviewing the docs for installation on the RVM website.
You can switch version between Ruby with $ rvm use --default 2.4.0 for example
But for your problem try this :
$ gem install bundler
$ gem install rails
Hope it helps !
I think below command will work
gem pristine rails
issue => can't find gem rails - Gem::GemNotFoundException
Solution for Mac M1 Chip
Remove Gemfile.lock
run rm Gemfile.lock
run bundle install
run pod update && pod install

Resources