Reputation: 23
I wanted to start a new rails project and decided to upgrade my Rails and Ruby versions. I started by upgrading Rails to 6.1.4 and later upgraded Ruby to 3.0.2 Before creating my new app I decided to check once more the version of Rails running and I had this error:
$ rails -v
Traceback (most recent call last):
2: from /Users/el/.rbenv/versions/2.6.5/bin/rails:23:in `<main>'
1: from /Users/el/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/Users/el/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)
I tried the create new rails app command and had the same error as below;
$ rails new tracking-app-api --api --database=postgresql
Traceback (most recent call last):
2: from /Users/el/.rbenv/versions/2.6.5/bin/rails:23:in `<main>'
1: from /Users/el/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/Users/el/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)
I ran the command $ gem update --system
and currently have:
gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.2.3
- RUBY VERSION: 3.0.2 (2021-07-07 patchlevel 107) [x86_64-darwin18]
- INSTALLATION DIRECTORY: /Users/el/.rvm/gems/ruby-3.0.2
- USER INSTALLATION DIRECTORY: /Users/el/.gem/ruby/3.0.0
- RUBY EXECUTABLE: /Users/el/.rvm/rubies/ruby-3.0.2/bin/ruby
- GIT EXECUTABLE: /usr/local/bin/git
- EXECUTABLE DIRECTORY: /Users/el/.rvm/gems/ruby-3.0.2/bin
- SPEC CACHE DIRECTORY: /Users/el/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/el/.rvm/rubies/ruby-3.0.2/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /Users/el/.rvm/gems/ruby-3.0.2
- /Users/el/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/el/.rvm/gems/ruby-3.0.2/bin
- /Users/el/.rvm/gems/ruby-3.0.2@global/bin
- /Users/el/.rvm/rubies/ruby-3.0.2/bin
- /Users/el/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/el/.rvm/bin
But I keep having the same error. I am using macOS Mojave
version 10.14.5
Thanks for your help.
Upvotes: 0
Views: 316
Reputation: 23
I ran gem install rails
and it fixed the issue. This is because I upgraded Rails before upgrading Ruby and as such my gem file
did not have the rails gem
. So I think it is advisable to always upgrade Ruby before upgrading Rails.
Upvotes: 1