Can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)

Viewed 36934

I am trying to build a new application or check the version of rails. I get the following error:

Traceback (most recent call last):
    2: from /usr/local/bin/rails:22:in `<main>'
    1: from /Users/vivanksharma/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:263:in `bin_path'
/Users/vivanksharma/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)

I searched many different solutions, but none of them worked for me.

Any help would be great.

ruby -v ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

rbenv -v rbenv 1.1.1

Even executing bundle install gives an error Could not locate Gemfile.

7 Answers

try to run gem install bundler then run bundle

if you still getting the error then run,

bundle install --path vendor/bundle

I'd to run rvm reset and it started working. The solution I found was connected with rvm warning "Warning! PATH is not properly set up, /Users/xxx/.rvm/gems/ruby-2.5.3/bin is not at first place.". (OSX Catalina)

I got the same error while creating a new gemset and querying the rails version. In my case, I simply had not installed the rails gem yet.
I just needed to do the following:

for a current stable release:
$ gem install rails

to get a specific version, say 5.2.2.0:
gem install rails --version=5.2.2.0

Hope that helps.

This will most likely happen when you try to install a gem without specifying a version of that gem against an older ruby version. The gem will attempt to install a newer version, meanwhile you are using an incompatible ruby version. So let's use Rails as an example. Let's say you are using an older Ruby version, such as 2.1. Then you cannot install the latest version of Rails. You would have to install an older version like Rails 4:

rvm-prompt
ruby-2.1.2
rvm gemset create validations_test
rvm use @validations_test

Install a version of bundler that works with the ruby version:

gem install bundler -v 1.17.3

Install Rails 4 which will work with Ruby 2.1:

gem install rails -v 4.2

Nokogiri will probably fail installing. So it will prompt you to install an older version of nokogiri:

gem install nokogiri -v 1.9.1

Now finish installing Rails (since Nokogiri would have haulted the completion of all the gems that need to be installed for Rails 4):

gem install rails -v 4.2

Now make sure when you create a new project, you are using Rails 4:

rails _4.2_ new validations_test 

My only problem was that I needed to run rails with bundle exec.

% rails g --help; echo $?
...
can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException)
1
% bundle exec rails g --help; echo $?
...
Usage: rails generate GENERATOR [args] [options]
...
0
  1. You should have a ruby version above 2.5.0
  2. Then run the command: gem update
  3. now create a new application.

When I added "sudo" I got it solved:

sudo rails -v
Related