Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbenv: rails: command not found #73

Closed
meleyal opened this issue Sep 2, 2011 · 85 comments
Closed

rbenv: rails: command not found #73

meleyal opened this issue Sep 2, 2011 · 85 comments

Comments

@meleyal
Copy link

meleyal commented Sep 2, 2011

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

@sstephenson
Copy link
Contributor

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.

@hovsater
Copy link

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?

@fearoffish
Copy link

I have the same issue with rspec. It's installed in 2 rubies but the 1.9.2 complains it doesn't exist and points me to the 1.8.7. If I gem install rspec and try again, same thing.

@ehogberg
Copy link

Am having the same issue with the Rails binary. Gem is installed; running rails w/ bundle exec works fine.

Running rbenv exec rails also works fine.

Running just rails complains that the Rails gem is not installed and that I should sudo gem install rails to make it available.

Other binaries (cap, rspec, cucumber) are all working fine w/out * exec help.

@hovsater
Copy link

I actually fixed this error by doing a manual install of rails gem install rails without using bundler. After that, running rails -v worked again and rbenv found my installation. So the trouble seems to happen with installing Rails through bundler.

@braidn
Copy link

braidn commented Sep 20, 2011

Hmm...wonder why this issue is closed? I just did a dry install of rbenv/ruby-build (no previous rvm) and shims are not being created for Bundled gems. When I run back and do gem install gem name, everything works great. Is this something that we should hold on for the next version?

@josh
Copy link
Contributor

josh commented Sep 20, 2011

This isn't an "issue". Bundler doesn't work this way.

See bundlers --binstubs flag.

@itgod
Copy link

itgod commented Sep 21, 2011

how about integrating https://github.com/carsomyr/rbenv-bundler ?

@josh
Copy link
Contributor

josh commented Sep 21, 2011

Sorry, but we're not adding anything bundler specific to rbenv.

@sstephenson
Copy link
Contributor

rbenv-bundler looks great -- but that's exactly why we have a plugin system in the first place. rbenv itself knows nothing about RubyGems or Bundler.

@minton
Copy link

minton commented Oct 4, 2011

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?

@braidn
Copy link

braidn commented Oct 4, 2011

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:
#73 (comment)

@minton
Copy link

minton commented Oct 4, 2011

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

@unicornrainbow
Copy link

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.

@olistik
Copy link

olistik commented Nov 23, 2011

@BlakeFrost: same for me, I've deleted that command too and everything just worked fine.

@rebelwarrior
Copy link

Same issue for me. This should not be closed.
I tried deleting the /usr/bin/rails command but still can't use it.
Get this error:
$ rails -v
-bash: /usr/bin/rails: No such file or directory
And before I got this:
rails c
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.

@olistik
Copy link

olistik commented Nov 25, 2011

@rebelwarrior put some context :-)

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

@rebelwarrior
Copy link

@mauriziodemagnis
rbenv version gets you the only one I've installed 1.9.3p0, same result w/ ruby-v, even after a rehash, gem list rails lists it. I've not clue what uname -a is or does so I've never run it (manning it now). -- Oh I'm on a MacBook OSX 10.6

I manage to fix the problem by sudo rm -rf /usr/bin/rails (and rake) and then reinstalling 1.9.3p0 with ruby_build again. Then closing the terminal and restarting it and it seems to work now. I need to test erb next since I didn't remove that one from /user/bin/ but I think the re-install fixed whatever issue I was having.

FYI I have jruby installed (not on rbenv but normal).

@gavinhughes
Copy link

I'm having similar problems to those described in this thread. I think rbenv needs better install/convert-from-rvm instructions to explain how things do/should work.

@derekprior
Copy link

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?

@justsee
Copy link

justsee commented Jan 25, 2012

Same problem as many here. Tried all suggestions, no luck, mystified, then blew away versions directory ~/.rbenv/versions/, rbenv install 1.9.2-p290, gem install rails, rbenv rehash, success.

@espen
Copy link

espen commented Jan 26, 2012

The problem seems to be when installing rails with bundler. I have specified rails in my Gemfile and this is the result for me:

bundle install
gem list rails

rails (3.1.3)
rbenv rehash
rails c
command not found: rails
gem uninstall rails
gem install rails
rvenv rehash
rails c
Loading development environment (Rails 3.1.3)

@graywh
Copy link

graywh commented Jan 26, 2012

@espen That is the documented behavior of bundler. Gems installed by bundler don't put their binaries in the shared bin directory (i.e. gem's EXECUTABLE DIRECTORY).

@espen
Copy link

espen commented Jan 27, 2012

So what is the best way of handling this? Use a gemset so there will be only one rails gem? Use bundler --path DIR to pack gems locally and use bundle exec rails ? Does rbenv or any plugins offer a best practice solution for this?

@graywh
Copy link

graywh commented Jan 27, 2012

gem install rails && rbenv rehash

Having multiple rails gems installed isn't a problem. Rails will load the version specified in Gemfile.lock.

Or you can bundle exec rails or use --binstubs to create ./bin/rails in your project.

@sanichi
Copy link

sanichi commented Jan 29, 2012

I can use rails inside a rails project using bin/rails (because I use --binstubs with bundler), for example

cd ~/Projects/my_app
bin/rails -v         # 3.2.1

But I don't seem to have a way to install the rails command outside of a rails project

cd
gem install rails    # installs 3.2.1 gem
rbenv rehash
which ruby           # /Users/mjo/.rbenv/shims/ruby
rbenv which ruby     # /Users/mjo/.rbenv/versions/1.9.2-p290/bin/ruby
rbenv which rails    # rails command not found
which rails          # /opt/local/bin/rails  (installed before I started using rbenv)
rails -v             # 2.3.5
echo $PATH           # /Users/mjo/.rbenv/shims:/Users/mjo/.rbenv/bin:/usr/local/bin:/opt/local/bin:......

@abepetrillo
Copy link

Can't seem to fix this, tried all the methods here with no success, switching back to rvm, much easier to use

@cschiewek
Copy link

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

@sanichi
Copy link

sanichi commented Feb 2, 2012

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

@dentarg
Copy link
Contributor

dentarg commented Nov 4, 2012

(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

@jmccartie
Copy link

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

@mousetree
Copy link

I had the same problem. Running 'rbenv rehash' fixed it

@lingmann
Copy link

People may be running into this as a result of a subtle environment differences between:

sudo rbenv rehash

and

sudo su -
rbenv rehash

In my environment, the second approach updates the shims while the first does not...

@jameswomack
Copy link

Some of you may have had this problem from not reloading your shell after installing.

@sosaucily
Copy link

@veilleperso ftw, thank you!

@iwan
Copy link

iwan commented Aug 12, 2013

+1 for the solution of quitting terminal (iTerm2) and starting it again - works fine now
Thank you

@evantravers
Copy link

For some of you… I had a .gem folder in my home… I rm'd it and problems went away. :-)

@ro5k0
Copy link

ro5k0 commented Nov 13, 2013

I'm getting exactly the same problem. I've tried everything above but none have worked. Really disappointed as I'm loathed to go back to rvm. Seems to only be a problem if I create a sub-folder in a folder withinin my Sites directory.

@mislav
Copy link
Member

mislav commented Nov 14, 2013

@Rosco77 Which rbenv version are you on? Check with rbenv version. If you gem install rails, does the installation complete successfully? Do rbenv rehash after that. Now if you try rails, do you get the same error?

Have you installed rbenv correctly?

@ro5k0
Copy link

ro5k0 commented Nov 15, 2013

It's a very weird scenario. The command "rails new myproject" works anywhere on my system as expected except when I try and run it when I'm in a child folder within the ./Sites directory. It works from "/Desktop/child-folder/third-level" or "~/rails-projects/child-folder" for example.

If I run rbenv version I get "2.0.0-p247 (set by /Users/rosco77/.rbenv/version)".

If I run gem install rails it installs successfully and I get the following message "Successfully installed rails-4.0.1
1 gem installed".

I've run rbenv rehash but still get the same error message of "Could not locate Gemfile" when I try and run the command in that specifc folder.

I've tried to delete the folder in question. Tried different names, etc, and it just doesn't work.

I've checked my installation and this is the output I get when I run echo $PATH | grep --color=auto "$(rbenv root)/shims":

"/Users/rosco77/.rbenv/shims:/Users/rosco77/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin."

I've attached an output of the results I get when I run "curl -s https://gist.github.com/mislav/4728286/raw/rbenv-doctor.sh | bash -x 2>&1". Any help you can give would be great.

screen shot 2013-11-15 at 16 42 39

@mislav
Copy link
Member

mislav commented Nov 15, 2013

Your issue is probably caused by the rbenv-bundler plugin that you seem to have installed. Related: #394

  1. rm ~/.rbenv/plugins/bundler
  2. rm ~/.rbenv/shims
  3. rbenv rehash
  4. Try again.

@ro5k0
Copy link

ro5k0 commented Nov 15, 2013

Many thanks @mislav that seems to have fixed it. 👍

@davemake
Copy link

gem install railties did the trick!

gem install railties && rbenv rehash

@tmartyny
Copy link

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

@mislav
Copy link
Member

mislav commented Jun 14, 2015

@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

@FWOliver
Copy link

First remove any previous docs of yaml by

cd .rvm/src
sudo rm -rf yaml*
Then you can do rest of the install by -

rvm pkg install libyaml

P.S You will need to reinstall ruby after this.

@mislav
Copy link
Member

mislav commented Oct 29, 2015

@FWOliver You seem to be using RVM, which is a different Ruby version manager than "rbenv", which is what we are discussing here.

@Kzai
Copy link

Kzai commented Nov 6, 2015

Hey - I am using zsh and was wondering why I am getting the following warning every time I launch terminal: /Users/user/.zshenv:2: command not found: rbenv

Everything appears to be fine and I am using rbenv to manage my versions with the following .zshenv file (did not work in .zshrc as suggested in various online resources.)

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
alias bex="bundle exec"

@mislav
Copy link
Member

mislav commented Nov 7, 2015

It seems that ~/.rbenv/bin/rbenv doesn't exist, which would suggest that perhaps you didn't install rbenv properly?

@Kzai
Copy link

Kzai commented Nov 9, 2015

Thanks @mislav . There is no /.rbenv/bin/rbenv - it doesn' t exist. The directory /.rbenv/ does exist and contains only plugins shims version versions.

Which ruby gives /Users/user/.rbenv/shims/ruby. I have been able to set the ruby version to 2.2.3 for a project I am working on and have been installing gems using bundle install. On investigation, the specific gems have been installing to ~/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems.
Seems strange to have a 2.2.0 directory within 2.2.3 directory.
Not really sure whats going on. I installed with homebrew.

@sebkkom
Copy link

sebkkom commented Dec 23, 2015

@mislav's solution did it for me as well but ~/.rbenv/shims is a folder so I had to type rm -rf ~/.rbenv/shims instead to make it work properly. Thanks a lot Mislav!

@kvokka
Copy link

kvokka commented Apr 15, 2016

@abcbots Thank you, man! It helps.

@sukhiTambar77
Copy link

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

@ghost
Copy link

ghost commented Mar 3, 2017

I got the same issue with Intellij IDEA, all I did was to change the SDK to 2.3.3 from 2.4
then $ gem install rails -> $ bundle install 😊Hope it helps

@jayapriyam
Copy link

gem install bundler

@oNguyenQuangVinh
Copy link

oNguyenQuangVinh commented Sep 19, 2017

you should copy part init rails from file bashrc to zshrc, i use gedit ~/.bashrc and gedit ~/.zshrc to open them.
like me :

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

hope it useful :)
sr if my english is very bad :(
thank for help me fix my english :)

@ccastillop
Copy link

Just in case. Working on Ubuntu 16.04
rbenv usually is installed using .bashrc
In my case, I added last lines also to .profile and now cron is working fine:

I added these lines to .profile, copied from .bashrc

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests