Setup RubyGems path in ubuntu

Building Virtual Machines (VM) using Vagrant this week. Unfortunately the Ubuntu Natty does not add Ruby Gems directory to system path variable. Using Ruby Gems on command line is tedious if you have to type the full path prefix everytime. For example I have to type /var/lib/gems/1.8/bin/vagrant .

Instead I used the solution suggested in libgems-ruby bug #145267 .



sudo echo "PATH=/var/lib/gems/1.8/bin:$PATH" > /etc/profile.d/rubygems1.8.sh 


Perhaps someone could add this to Vagrant Ubuntu installation documentation.

5 comments:

  1. Hi. According to the comment at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=403407#43 (reply number 43) this is no longer an issue with more recent versions of RubyGems (gem command) as the binary wrappers are now installed to /usr/local/bin/ which (at least on my system) IS on the system path.

    The problem now is that Ubuntu (and I suspect Debian) are using an old version (1.3.7 as of Ubuntu 11.04) of RubyGems where the newest at the time of this writing is 1.8.11 and so to get the upstream fix you need to either manually install the latest RubyGems or you need to update using "gem update --system" (which complains on Debian systems and requires you to set a variable first before it will allow it to proceed).

    One reason why this might be considered a bad idea to upgrade it rather than install it from scratch is that the package manager will still be free to mangle the shiny new RubyGems the next time the Debian system package version of it needs an upgrade unless you forcibly lock that package at it's current version and remember to stay on top of updating RubyGems manually via it's own means.

    Thus, my best recommendation if it's an option for you is to uninstall the Debian/Ubuntu version of RubyGems entirely and then install the most recent version from http://rubygems.org/ so that any gems you install will put their binaries on the system path in /usr/local/bin/ as they should be.

    ReplyDelete
  2. Thank you for very precise answer Anonymous :)

    ReplyDelete
  3. I have been away from programing for some time no 17 year . Last week or two I manage to install and run ubuntu on my windows 7 machine . Your right about the command line paths . Its hard to give any one a strait answer on how to use the command line to install any thing .As most of it depends on what version of software your using what cpu your running and 32 or 64 bit. Sorry its been a nightmare up to now. I just wanted to install ruby rubygems and rails i have accomplished most of this . But not all. Still cant get my ruby editor to work with the pritty color text I should have . It doz help when programing to see little mistakes as they happen. All of this I did in Hopes of writing and editing programs for a Phidget interface board SBC single board computer to run a bio char machine a friend . That I have yet to install there software . I made the switch to linux because I hated the way Micosoft is gouging eveyone for software addons. I will keep on banging away at it till it work the way it should.

    ReplyDelete
  4. Anonymous, Linux, OSX is follows the traditional UNIX design. So, you wouldn't have resort to command line quite often until MS Windows.

    Lately, Linux user experience is getting much better with valuable feedback from user and renewed focus on better UIs.

    ReplyDelete
  5. Thanks for this, I'm on lucid using the default ruby install and was looking for the correct way to get the path to gems set. I was surprised ubuntu didn't handle this already, thanks for the extra info about this.

    I think it's probably better/more correct to use single quotes so that $PATH isn't evaluated before it's put in the script. Better for it to be evaluated when the script is read ex:

    echo 'PATH=/var/lib/gems/1.8/bin:$PATH' > /etc/profile.d/rubygems1.8.sh

    also I think it likely needs to be executable

    chmod +x /etc/profile.d/rubygems1.8.sh

    cheers

    ReplyDelete

You can leave a comment here using your Google account, OpenID or as an anonymous user.