9

I've installed new Rails 3.1.3 using gem

# gem install rails

Then type:

wbednarski@mbp13:~$ rails
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.

More WTF:

wbednarski@mbp13:~$ which rails
/usr/bin/rails

How is it possible that command rails exist but Rails is not installed and how to fix it?

EDIT:

wbednarski@mbp13:~$ sudo gem install rails
Password:
Successfully installed rails-3.1.3
1 gem installed
Installing ri documentation for rails-3.1.3...
Installing RDoc documentation for rails-3.1.3...

then

wbednarski@mbp13:~$ 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.
Wojciech Bednarski
  • 5,046
  • 8
  • 46
  • 71

4 Answers4

3

I had similar problem on my Mac OS X (Lion)

According which rails I got path /usr/bin/rails So I made simple workaround:

  1. Find a proper rails bin file by $ find / -name rails or similar ("/usr/local/Cellar/ruby/1.9.3-p194/bin/rails" in my case )
  2. Make a backup for old file $ sudo mv -v /usr/bin/rails /usr/bin/rails_old
  3. Create symlink to proper rails bin file $ sudo ln -s /usr/local/Cellar/ruby/1.9.3-p194/bin/rails /usr/bin/rails

Should help.

Be aware! This is temporary solution and I don't think that is proper one. It's can be cause by ruby upgrading to version 1.9.3 using brew or something similar.

y4roslav
  • 347
  • 1
  • 3
  • 10
  • I haven't installed Ruby with Homebrew, but I know that generally Homebrew installs symlinks to the binaries in `/usr/local/bin`, so you should have a `/usr/local/bin/rails` which it's better to make a symlink to, than `/usr/local/Cellar/ruby/1.9.3-p194/bin/rails`. Then there's no need to change the symlink when you install a new Ruby version. Even better, just make sure `/usr/local/bin` comes before `/usr/bin` in your `$PATH`. Edit your `.bashrc` or `.zshrc` or similar. No need to use sudo. – dentarg Nov 04 '12 at 16:50
  • I know this solution but it doesn't work because rake, irb and other utility installed by Homebrew works well. Problem is just with ruby. – y4roslav Nov 04 '12 at 16:59
3

I would recommend not using the system installed ruby or install gems in the system directories. There are a couple projects out there for handling installations of different ruby versions and gems. The first and most well known is rvm. The other one I know about is rbenv. RVM might be a good choice to start with and you can decide later on if you want to try rbenv.

RVM is beneficial since it installs to your local home directory whichever ruby version you want and the gems too. This alleviates the issue of needing the correct permissions and $PATH issues.

Vincent Agnello
  • 485
  • 2
  • 8
  • thats for ruby... he's having a hard time with rails – bennett_an Dec 02 '11 at 20:43
  • 2
    It's not entirely answer why `/usr/bin/rails` is there and behave like is not. But using RVM is workaround for my problem. – Wojciech Bednarski Dec 04 '11 at 01:56
  • It's a waste of time to try and figure out why unless you really want to know. Personally, I would rather just get it working so I can actually get down to real work. Plus, there are several benefits to using RVM. The major one being that it allows you to try your code with several different Ruby implementations (JRuby, Rubinius, IronRuby, MRI, MagLev, MacRuby, Ruby Enterprise Edition). – Vincent Agnello Dec 05 '11 at 03:05
0

I had the same problem and the symlink hack failed. It was due to rbenv. I had installed Rails and rbenv a while ago, had added this line to ~/.bash_profile:

eval "$(rbenv init -)"

then I had commented it later on, and when I tried Rails again I got exactly the same symptoms. Uncommenting that line did the trick. See here and here for a similar issue and for tips with RVM.

miguelmorin
  • 3,611
  • 2
  • 15
  • 41
-1

Check you $PATH. /usr/local/opt/ruby/bin should be at beginning.

vim ~/.bash_profile

export PATH=/usr/local/opt/ruby/bin:$PATH
mrded
  • 3,500
  • 2
  • 27
  • 32