Now my issue is that if I try to install rails, which I do by typing: gem install rails, I get the following message: "-bash: /usr/local/bin/gem: /usr/local/bin/ruby: bad interpreter: Permission denied"

So the next logical move (for me) was to type: sudo gem install rails, but that returns "sudo: gem: command not found", which means I've screwed up something royally.

1 Answer
1

It seems you didn't uninstall the package that provides the gem executable, so it is still in /usr/local/bin/, and points to the no longer present /usr/local/bin/ruby interpreter.

You can either uninstall that package (recommended, since you've also removed the ruby package it depends upon), or just make sure ~/bin is before /usr/local/bin on your PATH. (Alternatively, if you have root access, you could just rerun the ./configure script without specifying --prefix=${HOME}, and let it install in /usr/local/bin, which is Ruby's default.)

Once you've arranged things so that your shell finds the gem executable installed in ~/bin, you should be able to simply gem install rails without needing sudo. (Or, if you go for the root install into /usr/local/bin, make sure gem is at /usr/local/bin/gem, and then run sudo gem install rails, as you tried before).

Possibly a better approach would have been to look at either rvm or rbenv, both of which make managing multiple rubies a fairly painless task. Using either of these tools, you can have several versions of ruby installed without the need to remove the system-wide one, which might be needed by other packages on the system.

Thanks for the clarifications. I went ahead and reconfigured and installed 1.9.2. I feel like this fixed my ruby issues because before when I looked up "which ruby" regardless of whether I was root or myself it pointed to my local directory, but now when I type which ruby as root I get /root/bin/ruby, which is good right? However, I still get "-bash: /usr/local/bin/gem: /usr/local/bin/ruby: bad interpreter: Permission denied" when I try to type "gem install rails". Any suggestions?
– mohsenJul 18 '12 at 17:01

Hmm. Sounds like you installed ruby into root's home directory. Is that what you did? If so, it's not really good, and I'd remove that particular install, then simply follow the instructions in the ruby distribution so it installs under /usr/local/bin. You can then install rvm or rbenv to manage rubies in your own home directory.
– D_ByeJul 18 '12 at 18:04