Fix error: can’t find executable rails

Posted . Visible to the public.

If you get an error like this ...

 can’t find executable rails for rails-3.2.3 (Gem::Exception)

... one of several things might be wrong.

  1. You're using RVM

It's possible that you have a system-wide gem executable (like rails) that requires a gem that is not available in the current RVM Ruby or gemset. Check what Ruby you are using (rvm current) and look out for .rvmrc files in your current directory (which change your Ruby upon entering the directory).

  1. You killed a gem install process

E.g. you hit CTRL+C while gem install xyz was running. Now your gems are in a weird, half-installed state. The only solution is to cleanly uninstall und reinstall whatever gem you didn't fully install:

sudo gem uninstall xyz
sudo gem install xyz

It's a little more complicated to cleanly reinstall Rails because it's composed of so many other gems. Something that worked for me was grep for the Rails version I'd like to reinstall:

gem list | grep 3.2.3

This gives you a long list of matching gems:

actionmailer (3.2.3, 3.0.12)
actionpack (3.2.3, 3.0.12)
activemodel (3.2.3, 3.0.12)
activerecord (3.2.3, 3.0.12)
activeresource (3.2.3, 3.0.12)
activesupport (3.2.3, 3.0.12)
rails (3.2.3, 3.0.12)
railties (3.2.3, 3.0.12)

Now you can uninstall it all:

sudo gem uninstall actionmailer actionpack activemodel activerecord activeresource activesupport rails railties

Now reinstall by simply saying:

sudo gem install rails
Henning Koch
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-05-18 10:16)