Installing gems to which Ruby with rbenv - ruby

How does one control which Ruby a gem is installed to using rbenv? Or could there be a central place accessible to all Rubies? I am just running Ruby scripts not Rails. rbenv-gemset seems to be for that?

The gem is installed into whatever your currently selected Ruby is. E.g.
rbenv shell 2.0.0-p247
gem install bundler # bundler is installed for Ruby 2.0.0-p247 only
rbenv shell 1.9.3-p447
gem install bundler # bundler is installed for Ruby 1.9.3-p447 only

Just to add on: rbenv-gemset would be for organizing your gems within the same ruby version. Only rbenv controls which ruby you install your gems to...

Related

Rvm version error

I have installed many flavors of ruby on rvm, and using following command to change rvm ruby versions.
rvm use 1.9.3
then ruby -v gives me following result
ruby 1.9.3p551 (2014-11-13 revision 48407) [i686-linux]
but when i try to run any commands like rails s or bundle install
it gives me following error
Your Ruby version is 2.3.1, but your Gemfile specified 1.9.3
Using
rvm list
you can get list of ruby version on your system along with current & default versions.
If ruby version is not specified in Gemfile, then it is generally considering default rvm version.
But if it is specified in Gemfile, then that version of ruby should be installed in your system along with its bundler.
First make sure ruby version either installing or using it,
rvm install '1.9.3'
rvm use '1.9.3'
To install bundle of required ruby version, run this command
gem install bundler
That's can happens, when you trying to use fresh installed ruby without bundler, all newest installed ruby should also include bundler installation.
$> rvm use 1.9.3 && gem install bundler # may terminal reload needed
$> bundle install
$> bundle exec rails s

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

What's the best way to upgrade to Ruby 2.3 through rvm while keeping all your gems installed on previous version (e.g. json, nokogiri, etc)?
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.

How to install active support with rbenv

I have setup ruby and rails using rbenv.
$ which ruby
~/.rbenv/shims/ruby
$ which rails
~/.rbenv/shims/rails
I want to install two gems i.e. activesupport and i18n. Is the procedure same i.e. Go to terminal> type the following:
$gem install activesupport
$gem install i18n
or for rbenv manager there is some other way? I don't want to break anything.
Details:
rbenv version 0.4.0.
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
I prefer to use a Gemfile in the directory of the project I am working on.
Your Gemfile might look like
gem 'activesupport'
gem 'i18n'
Then run
$ bundle install
This will pull the latest versions of these gems and save them according to your defined rbenv.
Not only that. In terms of your concerns about "breaking things", when you run bundle install a Gemfile.lock file will be created detailing the current versions of the gems used specific to the project of the directory you are working in.

How to install Bundler to #global gemset under RVM and is it a correct way

I am on OS X (if it matters).
If I install a Ruby using RVM, it will install Bundler by default to #global gemset
Let say I want a different version of the bundler. I assumed that all I needed to do is to execute
gem install bundler --version <SomeVersion>
However, this will install bundler to default gemset and RVM doesn't set a PATH to it.
As result, if I type bundler it will still launch a bundler which was installed with Ruby into #global
Two questions:
How can I install bundler to #global gemset.
Is this correct pattern to install bundler into #global gemset or I am missing something
This is how you can install bundler in the global gemset:
rvm #global do gem install bundler
as a practice, I don't see any issue, since bundler is never part of the gemfile in any case.
One glitch to note, if you have projects running multiple rails and ruby version (as old as 1.8.7 and rails 2.x) using newer bundler is not backwards compatible, so you'll be forced to use multiple bundler versions.

Installing gems in Mac OS X pre-installed ruby 1.8.7

Macs seem to all come with ruby 1.8.7 pre-installed. That's fine for my purposes, but when I install gems with either gem install gem-name or sudo gem install gem-name, I have to explicitly add the gem's lib directory to my $LOAD_PATH at the top of my ruby programs:
$LOAD_PATH.unshift File.join("/", "Users", "me", ".gems", "more_dirs", "lib")
Why do I have to do this? Am I installing gems wrong?
If I then install rvm and the latest ruby 1.9.3, I can install gems no problem with gem install gem-name.
With 1.8.7 where rubygems aren't built in. You need to
require 'rubygems'
at the top of your scripts in order to avoid manually setting the paths to your gems (pulling this in from the comments)

Resources