Installing Gems Using Rvm

installing gems using rvm

There's a permission issue with your .gem folder. Make sure the owner is your current user.

sudo chown -R tee /home/tee/.gem

If it doesn't work, remove the .gem folder. It is automatically created when you update the gem cache.

Also, make sure you never used sudo with rvm.

How do I install Ruby gems when using RVM?

It helps me to think of RVM as a layer of abstraction between you and the ruby ecosystem.

Without RVM: ruby, gems, and ruby related binaries (like rake, spec, gem, etc) are all installed directly into your operating system directories.

With RVM: ruby related stuff is intercepted by rvm so that ruby, gems, and ruby related binares are "installed" into ~/.rvm dir in a nice, clean, organized way. RVM sits between ruby, gems, and related binaries and the operating system. It provides a way to have multiple ruby environments (with different gems and binaries) on the same machine.

So, no matter whether you have rvm installed or not, you should be able to run the commands almost exactly(*) as they appear in any tutorials out there on the web. In other words, you can sort of "forget" that RVM is installed; the ruby ecosystem should work just as if it wasn't installed.

So, yep, you're gonna have to run gem install rails, etc.

Hope that helps clear the confusion.

(*) There are some small differences. For example: you shouldn't run commands as sudo when RVM is installed.

how can i install rubygems with rvm ? what is the difference between the two?

Yes, you can install gems with rvm. Use:

rvm use 1.9.2 # Make sure you're using the installed version
rvm gem install --version '3.0.3' rails

Updated to include specific version of the gem.

How do I use RVM and create globally available gems?

There is something called the global gemset, and it is shared between all your gemsets of a certain ruby-version. But you can't share gems between ruby-versions.

However, what you can do is create a list of gems that will be installed automatically when adding a new ruby version. That is described here. In short: edit a file called ~/.rvm/gemsets/global.gems to contain the list of gems you want to be there for each ruby-version.

Hope it helps.

Best way to upgrade to Ruby 2.3 through rvm while keeping all your gems?

EDIT

This question has an answer here: RVM: How to use gems from a different ruby?

$ rvm gemset copy $oldversion 2.3.0    ## Assign or replace $oldversion with old version name

ORIGINAL

Before installing Ruby 2.3, get a list of your installed gems and their versions using gem list. Then, after you install Ruby 2.3, use rvm to set 2.3 as the new default:

$ rvm install 2.3.0
$ rvm --default use 2.3.0

If you use Bundler, gem install bundler and then bundle install in all your project directories. This should install all of the gems relevant to your work.

If you don't use Bundler, or if you have gems installed that aren't part of any project's Gemfile, then you will want to go through the list of gems and their versions that you made earlier and gem install each of them, using -v to specify the version.

rvm 'gem install' wants to install latest gems. Can it be set to automatically install the latest compatible versions?

Gems have dependencies that may not be compatible with older versions of ruby (have methods that appeared in later versions of ruby). If you need to put this gem on your ruby version, you need to create a gemfile manually and register versions that are compatible with the new gem. Or install an older gem selenium-webdriver that fits Your version of ruby

bundle install and RVM

Look in rvm env gemdir, also check what you've got set in .rvmrc in terms of a gemset. Do bundle install and it should get all the gems.

Check .bundle by doing $ cat .bundle to see its content , and check if it is copying the gems to vendor/ruby. This will only be the case if bundle install --path vendor/ruby was supplied (Ref).

Setting up RVM for gem installs in future for correct permissions and adding PATH correctly

First, stop using --user-install. You shouldn't need it with RVM as that's one of its primary purposes, keeping the gems and Ruby in your home directory.

Your path is not well constructed:

"/Users/dhruv/anaconda/bin:/Users/dhruv/anaconda/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin:/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib"

Which breaks down to:

/Users/dhruv/anaconda/bin
/Users/dhruv/anaconda/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin
/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/Users/dhruv/.gem/ruby/2.0.0/bin
/Users/dhruv/scripts
/Users/dhruv/.rvm/bin
/Users/dhruv/.rvm/bin
/usr/local/lib
/Users/dhruv/.gem/ruby/2.0.0/bin
/Users/dhruv/scripts
/Users/dhruv/.rvm/bin
/Users/dhruv/.rvm/bin
/usr/local/lib

You need to have RVM first in the path but you're getting in its way.

It should look something like:

/Users/dhruv/.rvm/gems/ruby-2.2.1/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin
/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin
/Users/dhruv/scripts
/Users/dhruv/anaconda/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin

I'd rewrite ~/.bash_profile to:

source ~/.bashrc

export MONGO_PATH=/usr/local
export SBT_OPTS="-Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M -Duser.timezone=GMT"

export PATH=~/scripts:~/anaconda/bin:$PATH

# RVM needs to initialize last so it can adjust the path correctly...
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

I'd rewrite ~/.bashrc to:

# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

I'd rewrite ~/.profile to:

# export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

That should clean up your path, and probably will allow RVM to figure things out better.

You might need to do minor tweaks but keep it simple.

I'd recommend reading about how the shell uses PATH to find things and how to define PATH. Also, it'd be good to read about using ~/.bashrc, ~/.profile and ~/.bash_profile, especially on Mac OS. man bash at the command-line says, among other things:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if
that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one
that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

[...]

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the
--norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

When you install RVM using their default installation, it will create the ~/.rvm directory with the correct permissions. You won't have to do a thing after that to have RVM and Ruby store gems in that directory. Scripts will be able to find gems you've installed without you doing anything special with gem install. If it gets weird or hard something is wrong.



Related Topics



Leave a reply



Submit