2

I hope my title isn't confusing. I've got a CentOS 5 machine and I had Ruby 1.8.7 installed on here. So in order to upgrade my Ruby installation and gems/rails I

  • Uninstalled Ruby: sudo yum remove ruby

  • Downloaded the latest stable release of ruby and untared it: wget... && tar -zxf ....

  • Went through the usual installation:

    • ./configure --prefix=$HOME
    • make
    • sudo make install
  • Downloaded rubygems: wget....

  • ran the setup file: ruby setup.rb

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.

Just to add some more information

whereis ruby: ruby: /usr/lib/ruby /usr/lib64/ruby /usr/local/bin/ruby /usr/local/lib/ruby

which ruby: ~/bin/ruby

I'm thinking that by installing ruby manually from source I've screwed up something, perhaps the --prefix=$HOME is the culprit here?

1 Answer 1

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.

2
  • 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?
    – mohsen
    Jul 18, 2012 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_Bye
    Jul 18, 2012 at 18:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .