Question

I've already asked about installing python packages at $HOME. It worked flawlessly.

Now, I'm planning to install Vagrant. It's a gem (a ruby package), and I would like to install it in my $HOME folder as well but I'm not used to it so I'm asking for help here.

I've already run,

sudo gem update --system

As followed by their mac tutorial. And when I try to install Vagrant using their recomendation:

gem install vagrant

I get:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/bin directory.

(It's strange that just gem install vagrant doesn't work, I followed the guide from Vagrant's official website in a vanilla installed Mac, never used Ruby here and I got the error. Specially when using sudo is not required.)

Ok. Using sudo is going to resolve it, but I don't want to install this gem system wide, I want to install them at $HOME like I did with pip - and I have no idea how I can do it without messing up with this mac machine. Can someone help me how to do it the best way? Which variables to I have to export, if I have to add ~/.gem to my $PATH, or something like that. (Did I already messed everything up when I used sudo gem update --system?)

Some people are suggesting to use rvm, but I think this is overkill since I'm not going to develop ruby applications against the system Ruby, I just want to run Vagrant. Of course, if there isn't another way, I'm going to use it.

My gem environment command outputs:

gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.10
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-10
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/user/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

EDIT: I've found a tutorial, that says that I need just to add to my .profile:

export GEM_HOME=$HOME/.gems
export PATH=$GEM_HOME/bin:$PATH

Is it safe to use this approach?

Was it helpful?

Solution

Using the tutorial approach I posted it seems to work. I'm going to wait for more experienced ruby developers if this approach has any caveats in my scenario (I just want to run ruby applications, don't want to develop them) and them going to accept my own answer. :)

Transcripted tutorial:

Recommended: Installing Gems to Your Home Directory

Where possible, avoid installing gems into the global system. This ensures that the gems that you install are easy to identify and manage, and do not interfere with the global Ruby installation.

As of RubyGems 1.3, RubyGems will automatically install gems into the directory specified by the GEM_HOME environment variable if the system location is not accessible. You will see that directories are created within your GEM_HOME directory to store gem files. This means that RubyGems will do the right thing when managing packages, provided that you do not run the gem utility with administrative privileges.

To do this, edit the .profile file in your home directory, and add or amend it to include these lines:

export GEM_HOME=$HOME/gems

export PATH=$GEM_HOME/bin:$PATH

This takes effect the next time that you login or create a terminal window.

The presence of the bin subdirectory on your PATH enables you to use any command-line utilities that are installed with your gem packages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top