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)
Related
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
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.
I have selected a gemset with
rvm use ruby-2.1.2#deploy
in my gemfile I have:
gem 'transip', :git => 'git://github.com/rempargo/transip.git'
then I run bundle install and get the following output:
....
....
Installing wasabi 3.3.0
Installing savon 2.5.1
Using transip 0.4.2 from git://github.com/rempargo/transip.git (at master)
Using bundler 1.6.2
Your bundle is updated!
But when I do gem list all gems except the transip one are listed.
The other gems are not installed in gemset 'ruby-2.1.2' or 'ruby-2.1.2#global', but are really installed in the gemset ruby-2.1.2#deploy
I tried also to use bundle exec install although I never used the 'exec' before, but it does not work.
Is there a problem using bundler and rvm when using gems that uses a link to a repository?
I'm using:
Mac OS X 10.9.3 (With command-line tools installed)
rvm 1.25.26
bundler 1,6,2
P.S. This all happened after upgrading to Maverick, when some libraries where not working anymore, and I had to install ruby again with rvm.
gem list will show all the gems installed on your system
bundle show gem_namewill give you whether that gem is installed in your current application bundled gemset
I'm using Ruby 1.8.6 under RVM on Mac OS X (10.9.2). I installed everything as a local user (not root), and then installed a gem using:
gem install gli -v 1.6
When I run a ruby with require('gli'), I get the error:
in `require': no such file to load -- gli (LoadError)
even though gem list shows gli (1.6.0).
I don't know exactly how RVM does its gemsets, but there is no gli.rb file in any of the directories in the $LOAD_PATH.
How does RVM interact with the $LOAD_PATH to find the necessary gems in the gemset?
Try adding a require 'rubygems' at the top of your source file. In 1.8 rubygems aren't required by default.
Thus said, regarding gem paths:
GEM_HOME indicates where gems are installed. To find out what it is for your case do:
$ echo $GEM_HOME
This should display an RVM-related path, since RVM changes this environment variable in order to make the $ gem install command install gems in its directories.
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...