How to install Rails when dealing with "Load Error with Gems" - ruby-on-rails

I am trying to get Ruby on Rails working on my laptop and haven't been able to. At some point I took some bad advice and used sudo and have been trying to undo that error and the corresponding issues since.
As of right now, ruby -v shows
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
So, I think Ruby is installed. When I try to run gem install rails or any other gem command like gem install bundler, I get this error
Error loading RubyGems plugin "/Users/audreybrooke/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/executable-hooks-1.6.0/lib/rubygems_plugin.rb": cannot load such file -- executable-hooks/wrapper (LoadError)
Error loading RubyGems plugin "/Users/audreybrooke/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/gem-wrappers-1.4.0/lib/rubygems_plugin.rb": cannot load such file -- gem-wrappers (LoadError)
/Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
Traceback (most recent call last):
20: from /Users/audreybrooke/.rbenv/versions/2.7.1/bin/gem:21:in `<main>'
19: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/gem_runner.rb:44:in `run'
18: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/gem_runner.rb:79:in `do_configuration'
17: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/gem_runner.rb:79:in `new'
16: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/config_file.rb:182:in `initialize'
15: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/config_file.rb:332:in `load_file'
14: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems.rb:710:in `load_yaml'
13: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
12: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
11: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/yaml.rb:4:in `<top (required)>'
10: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
9: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
8: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/psych.rb:15:in `<top (required)>'
7: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
6: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
5: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/psych/nodes.rb:2:in `<top (required)>'
4: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
3: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
2: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/psych/nodes/node.rb:2:in `<top (required)>'
1: from /Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/audreybrooke/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': incompatible library version - /Users/audreybrooke/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/stringio-0.1.0/lib/stringio.bundle (LoadError)

It's because you have not installed libyaml correctly. Since you are using MacOS, maybe install it using homebrew can solve the problem.
brew install libyaml && brew link libyaml
I recommending to use rvm. It handle these like of dependency problems under the hood.

I did
sudo rm -rf ~/.rvm
because I had rvm and rbenv installed and that worked

Related

Problem making bundle install in the console when i change from ruby 2.3.7 to ruby 2.5

i already try a lot o diferent way but cant solve this problem
.it seems that i cant install gems but i cant figure out why
already try with gem install bundler but steel doestn work
taller_integracion git:(develop) bundle install
Traceback (most recent call last):
7: from /Users/seba/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
6: from /Users/seba/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
5: from /Users/seba/.rvm/gems/ruby-2.5.3/bin/bundle:23:in `<main>'
4: from /Users/seba/.rvm/gems/ruby-2.5.3/bin/bundle:23:in `load'
3: from /Users/seba/.rvm/gems/ruby-2.5.3/gems/bundler-0.9.26/bin/bundle:13:in `<top (required)>'
2: from /Users/seba/.rvm/gems/ruby-2.5.3/gems/bundler-0.9.26/lib/bundler/vendor/thor.rb:124:in `start'
1: from /Users/seba/.rvm/gems/ruby-2.5.3/gems/bundler-0.9.26/lib/bundler/vendor/thor/base.rb:377:in `start'
/Users/seba/.rvm/gems/ruby-2.5.3/gems/bundler-0.9.26/lib/bundler/vendor/thor/shell.rb:10:in `shell': uninitialized constant Thor::Base::Config (NameError)
and if i try with:
taller_integracion git:(develop) bundler install
Traceback (most recent call last):
10: from /Users/seba/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:10:in `<main>'
9: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/executable-hooks-1.6.0/lib/executable-hooks/hooks.rb:49:in `run'
8: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/executable-hooks-1.6.0/lib/executable-hooks/hooks.rb:49:in `each'
7: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/executable-hooks-1.6.0/lib/executable-hooks/hooks.rb:50:in `block in run'
6: from /Users/seba/.rvm/gems/ruby-2.5.3#global/gems/rubygems-bundler-1.4.5/lib/rubygems_executable_plugin.rb:4:in `block in <top (required)>'
5: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
4: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
3: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
2: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rubygems-bundler-1.4.5/lib/rubygems-bundler/noexec.rb:131:in `<top (required)>'
1: from /Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rubygems-bundler-1.4.5/lib/rubygems-bundler/noexec.rb:124:in `check'
/Users/seba/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rubygems-bundler-1.4.5/lib/rubygems-bundler/noexec.rb:84:in `setup': undefined method `rubygems' for Bundler:Module (NoMethodError)
I faced this problem. I was working on a small project hence I just updated ruby version in gemfile to 2.6.3 and it worked for me.
create a new gemset with this ruby version and then run
gem install bundler
to install bundler with the latest ruby.
Now run
bundle install
if bundle install does not work then try
bundle update
this should do the trick.
If you are still facing the same issue then let me know.

rails 5, rbenv - rails console doesn't start - Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)

When I run "rails c" command in terminal, somehow it doesn't start rails console and throws the error. I am running rails 5.2.2 with rbenv.
rails c
It throws the following error.
Running via Spring preloader in process 13912
Traceback (most recent call last):
50: from -e:1:in `<main>'
49: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
48: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
47: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
...
7: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
6: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
5: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
4: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
3: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
2: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
1: from /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require': dlopen(/Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
Referenced from: /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle
Reason: image not found - /Users/wemteq/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle
It worked a week ago, but not working now. Any ideas?
I found 2 solutions from some researching.
Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
libreadline.7.dylib is missing, so linking libreadline.8.0.dylib to libreadline.7.dylib worked for me.
ln -s /usr/local/opt/readline/lib/libreadline.8.0.dylib /usr/local/opt/readline/lib/libreadline.7.dylib
libreadline version might be different. You can browse available files in /usr/local/opt/readline/lib/ directory.
rb-readline gem in development group would fix this problem.
gem 'rb-readline'

Rails returns error when I try to create a new project

Rails broke on my system and now whenever I run rails new my_app it gives me a weird Thor error.
joshuahadik -> rails new hello_world
Traceback (most recent call last):
21: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
20: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
19: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/rails:23:in `<main>'
18: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/rails:23:in `load'
17: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/exe/rails:10:in `<top (required)>'
16: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
15: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
14: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/lib/rails/cli.rb:12:in `<top (required)>'
13: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
12: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
11: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/lib/rails/command.rb:9:in `<top (required)>'
10: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
9: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
8: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor.rb:2:in `<top (required)>'
7: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
6: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
5: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/base.rb:4:in `<top (required)>'
4: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
3: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
2: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/error.rb:1:in `<top (required)>'
1: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/error.rb:6:in `<class:Thor>'
/Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/error.rb:12:in `<module:DidYouMean>': uninitialized constant Thor::DidYouMean::SpellChecker (NameError)
I get the same error when I run pretty much any rails command, rails -v, rails s, etc.
So far I've tried a few things, including completely removing every version of ruby with rvm, then reinstalling them, then reinstalling the rails gem. Didn't work.
I really have no idea what's going on or why this is happening. Any help would be greatly appreciate.
UPDATE
Just realized that rails still works within the context of an existing rails project. So if I run rails s in the directory of a previously existing rails project it works just fine.
Thor is a gem that is used by Rails to show various command line messages.
It says you are using thor-0.20.1
I believe that version of Thor was released TODAY. The previous version, Thor-0.20.0 was released over a year ago. 0.20.0 is also the version I'm using.
It's likely that there is a bug in thor-0.20.1
You can try using bundler and your Gemfile to force your app to use thor-0.20.0
I ran into the exact same issue and rails wouldn't accept any command (rails s, rails new app) etc. Using ruby 2.5.3 and rails 5.2.1. It is due to the buggy thor-0.20.1
Therefore, reverted it back to thor-0.20.0 by:
- gem uninstall thor (but do not remove the executables when asked)
- gem install thor -v 0.20.1
It shall allow you to create a new project, however keep in mind that the Gemfile.lock file automatically changes the version to thor-0.20.1 (I don't know why). So be sure to change it back again to the 0.20.0.
A new version of thor has been released.
Just run:
gem update thor
The solution for me is delete the version gem Thor:
$ gem uninstall thor
Select gem to uninstall:
1. thor-0.20.0
2. thor-0.20.1
3. All versions
2
Successfully uninstalled thor-0.20.1

Error when creating a Jekyll project

When I run jekyll new . I have get this error:
Traceback (most recent call last):
11: from /usr/local/bin/jekyll:23:in `<main>'
10: from /usr/local/bin/jekyll:23:in `load'
9: from /var/lib/gems/2.5.0/gems/jekyll-3.8.3/exe/jekyll:8:in `<top (required)>'
8: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
7: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
6: from /var/lib/gems/2.5.0/gems/jekyll-3.8.3/lib/jekyll.rb:33:in `<top (required)>'
5: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
4: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
3: from /var/lib/gems/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:21:in `<top (required)>'
2: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
1: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
/usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require': cannot load such file -- public_suffix (LoadError)
error just for jekyll new . and jekyll new blog worked successfuly
( i tested jekyll new . --force but problem is unsolved
and my PATH is:
/home/shahrvand/.nvm/versions/node/v8.11.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/shahrvand/.gem/ruby/2.5.0
and my ruby version is:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
gem version : 2.7.7
jekyll 3.8.3
I'm using Ubuntu 18.04. What does this error mean?
Looks like you are missing the public_suffix gem. Try installing via gem install public_suffix or put it into your Gemfile and re-run bundle install.

Ruby installation missing psych, suggests reinstall of libyaml and ruby, and still have image not found? RailsTutorial

When using this command in the middle of my RailsTutorial ( on my laptop setup) :
rvm use 2.0.0#railstutorial_rails_4_0 --create --default
I receive the following errors:
laptop:rubygems-1.8.25 USER_NAME$ rvm use 2.0.0#railstutorial_rails_4_0 --create --default
Using /Users/USER_NAME/.rvm/gems/ruby-2.0.0-p451 with gemset railstutorial_rails_4_0
/Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/yaml.rb:4:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': dlopen(/Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/x86_64-darwin13.1.0/psych.bundle, 9): Library not loaded: /usr/local/lib/libyaml-0.2.dylib (LoadError)
Referenced from: /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/x86_64-darwin13.1.0/psych.bundle
Reason: image not found - /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/x86_64-darwin13.1.0/psych.bundle
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/psych.rb:1:in `<top (required)>'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/yaml.rb:5:in `<top (required)>'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems.rb:600:in `load_yaml'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/config_file.rb:314:in `load_file'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/config_file.rb:191:in `initialize'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/gem_runner.rb:66:in `new'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/gem_runner.rb:66:in `do_configuration'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/rubygems/gem_runner.rb:46:in `run'
from /Users/USER_NAME/.rvm/rubies/ruby-2.0.0-p451/bin/gem:21:in `<main>'
I've reinstalled libyaml, and reinstalled ruby, and it all returns back to these errors. No matter what I do, I always end up back at this list of errors.

Resources