rbenv: rbenv: rails: command not found

How do you run gem executables without Bundler / bundle exec?

~ $ rbenv rehash
~ $ rbenv global
1.9.2-p290
~ $ gem which rails
/Users/meleyal/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails.rb
~ $ rails new test
rbenv: rails: command not found

The `rails' command exists in these Ruby versions:
  1.8.7-p352

~ $ bundle exec rails new test
Could not locate Gemfile

Maybe related to #40, #61

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 85 (10 by maintainers)

Most upvoted comments

You need to gem install rails for every version of Ruby in which you want to use the rails command outside of a Bundler project. Looks like you have it installed for 1.8.7-p352, but not 1.9.2-p290.

gem install railties did the trick!

gem install railties && rbenv rehash

Not to keep things running but did you perform rbenv rehash?

On Tue, Oct 4, 2011 at 12:56 PM, Michael Minton < reply@reply.github.com>wrote:

I just did a fresh install of Lion. After installing rbenv, ruby and rails I am unable to run rails from terminal. It simply states “Rails is not currently installed…”. However, I can run rbenv exec rails with no problem. Any suggestions?

Reply to this email directly or view it on GitHub: https://github.com/sstephenson/rbenv/issues/73#issuecomment-2288674

I had the same issue and I solved it by reinstalling railties (instead of rails) as the rails binary is in railties gem:

$ gem install railties && rbenv rehash

Turns out you need to use rbenv exec to get the rails binary in the right spot: rbenv exec gem install rails

Had this problem. @veilleperso 's solution worked for me.

$ rails -v
Rails 2.3.14

$ gem install railties && rbenv rehash

(then completely close terminal and reopen)

$ rails -v
Rails 3.2.9

I did.

Update: I installed via Homebrew and missed that you have to manually add eval "$(rbenv init -)" to your profile. That’s very likely your problem as well Eric. /sigh

I actually got the same problem today. I’ve got Rails installed for both my rails versions but I still get the following while running rails -v in other versions except 1.8.7.

rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
  1.8.7-p352

Standing in my current project having a .rbenv-version file containing 1.9.2-p290 and running rbenv rehash and gem list rails I get the following output:

 rails (3.0.9)

I double checked to see if this is the right Ruby version by doing rbenv version and got the following output:

1.9.2-p290 (set by /Users/kevin/Sites/Rails/kryast/.rbenv-version)

Any ideas on the problem?

I had the same or similar issue…

> rails
Rails is not currently installed on this system. To get the latest version, simply type:

    $ sudo gem install rails

Turns out I had something at /usr/bin/rails. I’m not really sure where it came from, but I sudo rm’d it FTW. Hope it helps.

New install of rbenv and freshly built rubies. Set 1.9.3 to be my global ruby. Then tried:

➜ gem install rails
...
➜ rbenv rehash
➜ rails -v
Rails is not currently installed on this system. To get the latest version, simply type:

    $ sudo gem install rails

You can then rerun your "rails" command.
➜  rbenv versions
  1.8.7-p352
  1.9.2-p290
* 1.9.3-p0 (set by /Users/dprior/.rbenv/version)
  ree-1.8.7-2010.01
➜  which rails
/Users/dprior/.rbenv/shims/rails

If I open a fresh terminal, though, rails -v reports the correct version. What the heck is going on here? Any ideas?

@rebelwarrior put some context 😃

$ rbenv versions $ ruby -v $ rbenv rehash $ gem list rails $ uname -a

when i run chef-client with then i am getting this error even though i have installed 2.1.0 and 2.3.1 both ruby version using rbenv.

The `bundle’ command exists in these Ruby versions: 2.1.0 stuck with this issue, can anyone help me

@tmartyny You have to install Bundler for each Ruby version just intend to use it on. When you did rbenv global 2.2.2 that doesn’t mean that the global version applied to your current directory. Maybe there was a .ruby-version file in the local directory specifying a different Ruby version. In any case, you can install bundler for all Ruby versions with:

for ver in `rbenv versions --bare`; do RBENV_VERSION=$ver gem i bundler; done

I had the same issue and the solutions above didn’t fix my problem. This error came up for me after upgrading my global Ruby version to 2.2.2. After upgrading I had to run:

rbenv shell 2.2.2

once I set that, I was then able to install bundler and then bundle in my app directory. Here is the stackoverflow post that helped me: http://stackoverflow.com/questions/17562426/installing-gems-to-which-ruby-with-rbenv

(I’m using zsh.) Instead of quitting your shell, run eval "$(rbenv init -)". It seems to update zsh completions and that makes my shell find the right rails (~/.rbenv/shims/rails). I wonder why rbenv rehash didn’t solve this.

Edit:

I can’t repeat it, now rbenv rehash works fine:

$ gem uninstall rails railties 
Successfully uninstalled rails-3.2.8
Remove executables:
    rails

in addition to the gem? [Yn]  y
Removing rails
Successfully uninstalled railties-3.2.8
$ eval "$(rbenv init -)"       
$ rails -v
Rails is not currently installed on this system. To get the latest version, simply type:

    $ sudo gem install rails

You can then rerun your "rails" command.
$ gem install rails            
Fetching: railties-3.2.8.gem (100%)
Fetching: rails-3.2.8.gem (100%)
Successfully installed railties-3.2.8
Successfully installed rails-3.2.8
2 gems installed
$ rails -v
Rails is not currently installed on this system. To get the latest version, simply type:

    $ sudo gem install rails

You can then rerun your "rails" command.
$ rbenv rehash
$ rails -v    
Rails 3.2.8

yeah, just quit Terminal and opened a new shell.

Thansk for the suggestion but it doesn work for me:

cd
rbenv exec gem install rails  # install's 3.2.1 gem
rbenv rehash
rbenv which rails             # rbenv: rails: command not found

I just did a fresh install of Lion. After installing rbenv, ruby and rails I am unable to run rails from terminal. It simply states "Rails is not currently installed...". However, I can run rbenv exec rails with no problem. Any suggestions?