rails rbenv: rails: command not found
Solution 1
After installing a gem via the command line in a ruby version you have to execute rbenv rehash
as described in the docs here and here
For example:
$ rbenv install 2.2.0
$ gem install bundler
$ rbenv rehash
$ gem install rails
$ rbenv rehash
Solution 2
You need to install Rails for each Ruby version within rbenv
. Try running rbenv version
, I might expect that 2.1.2 is not the ruby version in use for the current project (local version) or maybe your global version.
Solution 3
I ran into the same issue, but none of these other solutions (or any of the others I found elsewhere) worked. I was about to go back to RVM, so I decided to get rid of rbenv completely and it paved the way to the solution.
Try the following - it worked for me:
uninstalling rbenv, remove all references rbenv in your bash profile, and remove the remaining rbenv file folder and its contents.
Reinstall rbenv with homebrew.
-
Add it back to your bash profile:
export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH" eval "$(rbenv init -)"
-
Restart the shell:
exec $SHELL -l
-
Check the path:
echo $PATH
-
Install Rails:
gem install rails
rbenv rehash
Note: I consulted this for part of this answer: https://www.codementor.io/tips/3732499178/solution-for-rbenv-rails-is-not-currently-installed-on-this-system-to-get-the-latest-version-simply-type
Solution 4
Try to set up your environment with 2.1.2 version running this command line in your terminal:
$ rbenv shell 2.1.2
It works to me
Solution 5
For me, I set up my environment with the listed "The `rails' command exists in these Ruby versions".
$ rbenv shell 2.1.2
$ rails -v
It works.
Boss Nass
BY DAY: Alt-Rock Ninja Cowgirl at Veridian Dynamics. BY NIGHT: I write code and code rights for penalcoders.example.org, an awesome non-profit that will totally take your money at that link. My kids are cuter than yours. FOR FUN: C+ Jokes, Segway Roller Derby, NYT Sat. Crosswords (in Sharpie!), Ostrich Grooming. "If you see scary things, look for the helpers-you'll always see people helping."-Fred Rogers
Updated on May 26, 2021Comments
-
Boss Nass almost 3 years
I have recently moved from RVM to Rbenv and when attempting to execute rails I am getting an error like the one below
Pauls-Air:~ $ rails rbenv: rails: command not found The `rails' command exists in these Ruby versions: 2.1.2
-
user2101068 almost 7 yearsYes you are correct. That is insane! If RVM doesn't require doing the same that alone is justification to dump rbenv and switch to RVM. Does anybody know?
-
eebbesen over 2 yearsI found that uninstalling and re-installing rbenv solved this for me. I didn't need to remove rbenv-specifics from .zshrc, but I did manually delete ~/.rbenv after uninstalling and before re-installing rbenv via homebrew.
-
stormdrain over 2 yearsYou can also add rails to the version you are trying to use:
rbenv shell 2.7.1
then rungem install rails
.