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
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.
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 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.
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.
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.
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?
This isn't an "issue". Bundler doesn't work this way.
See bundlers --binstubs flag.
how about integrating https://github.com/carsomyr/rbenv-bundler ?
Sorry, but we're not adding anything bundler specific to rbenv.
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.
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?
Not to keep things running but did you perform rbenv rehash?
On Tue, Oct 4, 2011 at 12:56 PM, Michael Minton <
[email protected]>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 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 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.
@blakefrost: same for me, I've deleted that command too and everything just worked fine.
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.
@rebelwarrior put some context :-)
$ rbenv versions
$ ruby -v
$ rbenv rehash
$ gem list rails
$ uname -a
@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).
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.
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?
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.
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)
@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).
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?
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.
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
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:......
Can't seem to fix this, tried all the methods here with no success, switching back to rvm, much easier to use
Turns out you need to use rbenv exec to get the rails binary in the right spot:
rbenv exec gem install rails
Thansk for the suggestion but it doesn work for me:
rbenv exec gem install rails # install's 3.2.1 gem
rbenv rehash
rbenv which rails # rbenv: rails: command not found
Thanks for the suggestion cschiewek but still doesn't work for me:
rbenv exec gem install rails # installs 3.2.1
rbenv rehash
rbenv which rails # not found
None of the solutions worked for me...
I had to run rails in the context of bundler every time until I reinstalled ruby. Then, instead of rushing and bundle in my project dir, I installed rails by gem install rails and then I bundled the rest of the gems I need. This seems to solve the rails executable problem for me.
This has happened a second time on a fresh dev machine, and I also now suspect as @muxcmux appears to that if you run bundle on a project before doing gem install rails, then all attempts to gem install rails will fail. I've resolved both times by blowing away all of rbenv, reinstalling, and making sure I gem install rails first before executing any project bundle actions.
I too experience this issue. No solution found so far. I had an old version of rails installed (3.1.3), in ~/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rails-3.1.3/bin a binary called rails is found. When installing a new version of Rails (3.2.1) the directory was created be remained empty.
+1
if rails project installed: RAILS_APP/script/rails
I had the same experience as @haarts. rbenv seemed to install the latest Rails (3.2.1) but the directory /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rails-3.2.1/ was empty instead of containing a bin directory.
To work around the problem, I created a new directory where I wanted my Rails 3.2.1 app, containing a Gemfile with the single line gem 'rails', '3.2.1'. I then bundled it and ran rails new myapp to get an app skeleton. I.e.:
$ mkdir tmp
$ cd tmp
$ echo 'gem "rails", "3.2.1"' > Gemfile
$ bundle
$ bundle exec rails new myapp
$ mv myapp ..
$ cd ..
$ rm -r tmp
I was having this same issue. I tried removing /usr/bin/rails and redoing gem install rails, but rbenv still complained about rails not being installed. I saw minton's comment about eval "$(rbenv init -)" and double checked that in fact it was added to my profile. I then restarted my terminal, and what do you know, it worked! So I'm wondering if the eval "$(rbenv init -)" needs to be run again?
I tried uninstalling and trying it again to test my theory. The rails gem was supposedly uninstalled, but rbenv was still finding rails somewhere. Does anyone else find it works with running eval "$(rbenv init -)" again (or at least by restarting the terminal)?
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
Installing railties did the trick for me, thanks @veilleperso!
Oh yeah! Thank you veilleperso!
Thanks @veilleperso this works fine for rails, but what we can do for rspec?
For rspec, try:
gem uninstall rspec rspec-core
gem install rspec
rbenv rehash
Worked for me.
Yah.. work for me too!! Thank's @rssaddict!!
Actually, after pulling the latest version of rbenv, this appears to no longer be an issue with 0.3.0 ... can anyone confirm that?
No. For me the issue was still present, started just using rbenv today. Did run bundle in project directory before doing gem install rails. @veilleperso solution worked, thanks.
The same as @rzmz. Thanks @veilleperso for the trick :-).
Thanks @veilleperso, it worked like a charm!
gem installing railties again worked for me too. Anone have any idea why?
I installed rbenv (per the instructions), installed ruby 1.9.3-p125 and ran rbenv rehash. Then I ran 'gem install rails' and once installed, I ran rbenv rehash once more. Then I COMPLETELY quit out of Terminal and re-opened it and ran 'rails -v' and it worked. For me, the key was completely quitting out of Terminal and then re-opening again. Hope this helps someone.
yes I did the same, add gemfile to blank dir, bundle then rails new testapp
I tried upgrading (git pull on .rbenv) and installing latest ruby and rbenv rehash but no joy
Hope this helps someone: In my case, I was following instructions about using rvm to install rails (http://spyrestudios.com/setting-up-a-rails-development-system-on-mac-osx-snow-leopard/). And having virtually no idea what I was doing, I got very stuck when I opened a second terminal window and couldn't access rails.
To correct this, I first had to fiddle with my shell files to make sure the paths were getting added. But the key thing was typing the 'rvm use 1.9.[email protected]' command. Once I did this, I suddenly got back everything I had already installed.
@senortim Sir, when you have no idea what you are talking about, it's often better not to say anything at all.
I follow what @fernandoaleman mentioned for restart terminal, at first time have no luck, but after I try again, it just works.
+1 for the solution of quitting terminal (iTerm2) and starting it again - works fine now
$ rbenv version
1.9.3-p0 (set by /Users/jones/.rbenv/version)
$ which rails
/Users/jones/.rbenv/shims/rails
$ rails -v
Rails 3.2.5
This is on Mac OS X Lion
I have just experienced this issue. I use Mac OS X Lion.
After a couple of hours of googling and struggling, I found why it was happening. The culprit causing this problem was the $GEM_HOME environment variable. That pointed the old ruby get directory so the gem I was executing was from under this $GEM_HOME hierarchy somewhere. That gem is for Mac's default ruby installation. So no matter how many times I execute 'gem install rails', the rails was also installed under $GEM_HOME. That is why the command was not found and always came back with the 'command not found' message.
What you need to do is unser GEM_HOME, and install rails again. This way rails will be installed under .rbenv/somewhere and 'rails -v' will show the version number.
yeah, just quit Terminal and opened a new shell.
Thanks @dukejones & @nodayoshikazu. I felt like an idiot until I saw this.
{12-10-03 13:15}[1.9.3-p194]vps:~ carcia% which rails
rails not found
{12-10-03 13:15}[1.9.3-p194]vps:~ carcia% gem install rails
Successfully installed rails-3.2.8
1 gem installed
{12-10-03 13:16}[1.9.3-p194]vps:~ carcia% which rails
rails not found
{12-10-03 13:16}[1.9.3-p194]vps:~ carcia% rbenv rehash
Could not load the bundler gem for Ruby version 1.9.3-p194.
{12-10-03 13:17}[1.9.3-p194]vps:~ carcia% which rails
rails not found
(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
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 had the same problem. Running 'rbenv rehash' fixed it
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...
Some of you may have had this problem from not reloading your shell after installing.
@veilleperso ftw, thank you!
+1 for the solution of quitting terminal (iTerm2) and starting it again - works fine now
Thank you
For some of you… I had a .gem folder in my home… I rm'd it and problems went away. :-)
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.
@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?
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.

Your issue is probably caused by the rbenv-bundler plugin that you seem to have installed. Related: #394
rm ~/.rbenv/plugins/bundlerrm ~/.rbenv/shimsrbenv rehashMany thanks @mislav that seems to have fixed it. :+1:
gem install railties && rbenv rehash
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
@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
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.
@FWOliver You seem to be using RVM, which is a different Ruby version manager than "rbenv", which is what we are discussing here.
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"
It seems that ~/.rbenv/bin/rbenv doesn't exist, which would suggest that perhaps you didn't install rbenv properly?
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.
@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!
@abcbots Thank you, man! It helps.
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
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
gem install bundler
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 :)
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 -)"
Most helpful comment
You need to
gem install railsfor every version of Ruby in which you want to use therailscommand outside of a Bundler project. Looks like you have it installed for 1.8.7-p352, but not 1.9.2-p290.