Ruby and Rails Error (Psych::SyntaxError) and - ruby-on-rails

After experiencing some issues with my ruby.framework I deleted it and used pacifist to reinstall and that seemed to solve my previous issue. Now I seem to always get this error when using ruby with any command.
/Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/psych.rb:370:in `parse': (<unknown>): mapping values are not allowed in this context at line 2 column 7 (Psych::SyntaxError)
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/psych.rb:318:in `parse'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/psych.rb:245:in `load'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/config_file.rb:333:in `load_file'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/config_file.rb:198:in `initialize'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/gem_runner.rb:74:in `new'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/gem_runner.rb:39:in `run'
from /Users/brandoncontreras/.rvm/rubies/ruby-2.1.3/bin/gem:21:in `<main>'
It only occurred after I tried to set ruby 2.1 as the default ruby version
brandons-mbp:~ brandoncontreras$ ruby -v
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
brandons-mbp:~ brandoncontreras$
All other threads had solutions that didn't fix the problem.
I also have xcode installed with a fresh command line developer tools install.
Been trying to set up environment on mac for a 10 days....
EDIT:
tried looking to see what was in my config_file.rb and added puts filename...what am I looking for? and i do not have a credentials file in my .gem folder

Related

Rails + Big Sur + pg and Spring conflict?

Once I upgraded to Big Sur, I immediately got the following error in Ruby on Rails when launching the server:
$ rails s
/Users/carsoncole/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/x86_64-darwin19/stringio.bundle: warning: already initialized constant StringIO::VERSION
You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).
This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.
Here's the backtrace:
/Users/carsoncole/.rvm/gems/ruby-2.7.1/gems/bootsnap 1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/Users/carsoncole/.rvm/gems/ruby-2.7.1/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/Users/carsoncole/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `block in load'
/Users/carsoncole/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/carsoncole/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `load'
/Users/carsoncole/.rvm/gems/ruby-2.7.1/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<main>'
/Users/carsoncole/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/carsoncole/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/carsoncole/scout_activity/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
I followed the directions given above but to no avail. Any thoughts?
If I create a new Rails app, the server starts up fine. Using Rails 6.0.3.4 and Ruby 2.7.3
One difference between the new app and my existing app is the new app did not use 'pg'. When I added 'pg' (pg-1.2.3) to the new app, the same error occurs.
[UPDATE] I think the issue may be related to Homebrew. I'm now reinstalling.
I found a solution, although I can’t pinpoint exactly why it worked.
I reinstalled Homebrew, and Posgresql (with HB). I also updated Xcode and the command line libraries. In the process of reinstalling homebrew and Xcode, I believe a number of libraries were updated/installed which I suspect was the issue.
Works fine now.

why all of my Gem commands are suddenly not working?

I started receiving the following every time i wanted to write any gem command:
Traceback (most recent call last):
8: from C:/Ruby25-x64/bin/gem:9:in `<main>'
7: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
6: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
5: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/gem_runner.rb:86:in `<top (required)>'
4: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems.rb:1140:in `load_plugins'
3: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems.rb:556:in `find_latest_files'
2: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1156:in `latest_specs'
1: from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1173:in `_latest_specs'
C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1173:in `sort_by': comparison of Array with String failed (ArgumentError)
I solved the issue. I was actually learning ruby on rails and to cope with the course i started a new rails application with MySQL and started a rails server in the root of the project however it didn't worked because it wasn't able to locate the gem. One of the solutions i found online was to edit the MySQL .gemspec file however it made things worst and suddenly no gem command was running anymore. I solved the issue by uninstalling ruby and then installing it again and also installing the gems again (including rails)

Rails not running after Ruby update (possibly RVM related)

I resorted to upgrading Ruby from 2.3.0 to 2.3.1 because of a really weird error I was getting and not being able to even come close to finding more info around google/SO.
Now after trying to figure this out I am getting this error whenever I try to run the project, or run bundle or rails in bash
/usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require': cannot load such file -- bundler (LoadError)
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.16.0/exe/bundle:10:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/bin/bundle:23:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/bin/bundle:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
I have already tried reinstalling Ruby, RVM, bundler, but the error persists. I cannot find much info on that specific error around the web so I hope someone can help me troubleshoot this through here. Let me know if there are any specific logs I can provide and I will happily add more info.
EDIT:
I just noticed the path is ...ruby-2.3.1/lib/ruby/ 2.3.0 ... (the difference of 2.3.1 and 2.3.0)
When I upgraded to 2.3.1 I uninstalled previous versions. Could that be an issue since the error comes from a path that refers to a non-existing version of ruby?
Not sure why all this happened and what was wrong with the bundler, but what ended up fixing it for me was this command:
gem update --system

I am trying to install Rails on Mac however it wont let me

I am trying to install Rails on my Mac however everytime i try to install it I receive this:
$ gem install rails
/Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:369:in `parse': (<unknown>): mapping values are not allowed in this context at line 2 column 4 (Psych::SyntaxError)
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:369:in `parse_stream'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:317:in `parse'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:244:in `load'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:332:in `load_file'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:197:in `initialize'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `new'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:39:in `run'
from /Users/macbook/.rvm/rubies/ruby-2.1.0/bin/gem:21:in `<main>'
I have searched hours trying to figure this out so any help would be greatly appreciated. I take it this is a simple fix, so apologize in advance for this easy question.
It could be that you are using newer version of ruby i.e 2.1.0 which was just released today and the relevant gems for rails are not fully compatible with it.
You can install rails in ruby 2.0.0 through RMV i.e
$ rvm install 2.0.0
$ rvm use 2.0.0
$ ruby -v
# should retrun 2.0.0-p...
$ gem install rails

undefined method `source_index' for Gem:Module (NoMethodError)

I'm running a Rails 2.3.5 application and upon running script/server I am shown the following:
./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
from ./script/../config/boot.rb:60:in `load_initializer'
from ./script/../config/boot.rb:44:in `run'
from ./script/../config/boot.rb:17:in `boot!'
from ./script/../config/boot.rb:123
from script/server:2:in `require'
from script/server:2
If I comment out line 60 in boot.rb (Rails::GemDependency.add_frozen_gem_path) and run script/server, I get this:
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:298:in `add_gem_load_paths'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:132:in `process'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /home/developer/bigpink/config/environment.rb:13
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/developer/bigpink/vendor/rails/railties/lib/commands/server.rb:84
from script/server:3:in `require'
from script/server:3
So, not really sure what to do. Hoping I can get some quick help. Thanks!
I just ran into this problem myself while trying to upgrade an older Rails app from REE 1.8.7 to 1.9.3-p385. Oddly, Ruby 1.9.3-p327 works just fine. What it came down to was ruby-1.9.3-p385 had installed RubyGems version 2.0.2 for me, and 1.9.3-p327 has RubyGems v1.8.23 installed.
Gem.source_index has been deprecated for a while, but since Rails 2.3 is not getting any updates except critical security patches, this will never get fixed. RubyGems v2.0 finally removed that method. Downgrade to any rubygems version prior to 2.0.0, like 1.8.25 to get the functionality back for now. You can get a compatible version using gem update --system 1.8.25.
As a very important aside, Rails 2.3.5 needs to be updated to a minimum of 2.3.17. There are critical security vulnerabilities that open you up to some very nasty attacks. In the long term, upgrading to 3.x needs to be considered a very strong need.
for rvm users,
rvm install rubygems 1.8.2 --force
This helped me: http://djellemah.com/blog/2013/02/27/rails-23-with-ruby-20/
I did this in combination with gem update --system 1.8.25, which might not be needed for your case.
Another way to do this is to install slimgems: gem install slimgems. This is a drop-in fork of RubyGems that works better with old versions.
Update: In addition to the #uxp answer, if you running this command on a Mac running Catalina, there is a small change in command, you need to add -n.
So the command would be sudo gem update --system -n 1.8.25

Resources