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.
RVM | Obtrusive gems in the global gemset
this gems are part of ruby distribution:
bigdecimal (1.2.3)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.2)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.0.0)
this gem is part of rvm and is required for rvm to function properly:
gem-wrappers (1.2.3)
RVM global gemset confusion
In common:
rvm <ruby version>@<gemset name> do gem list
For example:
rvm @test do gem list
show that you want: gems on test gemset environment
Another way:
rvm use @test
gem list
show the same
Gem installed in @global gemset is not available in other gemsets
looks like your GEM_PATH
is broken, pleas run:
export GEM_PATH=/Users/andy/.rvm/gems/ruby-2.2.3:/Users/andy/.rvm/gems/ruby-2.2.3@global
and try again:
bro
RVM system-wide gemsets
Use mixed mode installation of RVM basically you get system installation and as every user that should have his own gemsets run:
rvm user gemsets
Whats the command to let rvm use default (like global) gemset for every new rails application I create?
You can specify a "default" gemset for a given ruby interpreter, by doing:
rvm use ruby-1.9.2-p0@gemsetname --default
See: http://beginrescueend.com/gemsets/using/ and http://beginrescueend.com/gemsets/basics/
it's probably a better idea to use a specific gemset for each of your projects, together with it's specific Gemfile. Problems could happen if you require '>= x.y.z' in your Gemfiles, and you do a bundle update
in one project, but not in the other...
cd ProjectA
rvm gemset create projecta
rvm gemset use projecta
cd ProjectB
rvm gemset create projectb
rvm gemset use projectb
This way, although you update the gems in ProjectA via bundle update
to the latest and greatest, they still don't get modified for ProjectB -- eliminating the possibility for interference between projects.
you can also add a .rvmrc file to a directory, e.g. your project directory. RVM will then use the ruby-version and gem set listed in the .rvmrc file as the default for all sub-directories.
e.g. assuming that you have ruby 1.9.3 installed, and a gem set "rails_3.2" for that ruby version:
# cat .rvmrc
rvm use ruby-1.9.3-p0@rails_3.2
How to reduce duplicate gems with RVM and Bundler?
If you wanna install a gem per ruby, you need to do a gem install pry
for instance. That will install the gem on the ruby level. After that you can require that in your Rails app, for instance on the boot.rb
file.
I am not sure how rvm deals with gemsets. If what they do is change the entire folder reference of the gem
command, then you wont be able to do that. I would need to install those gems for every gemset, which is a PITA.
On my workflow, I dont need gemsets, as I have bundler. So I use rbenv to install and change ruby versions, and let bundler deals with gems for a project. Like so, I can install a gem, globally per ruby, and it works.
How do RVM rubies find gems?
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.
Globally available Gemfile
Make a Gemfile as usual, and place it in any folder. It does not need to be a project folder. Then you can just do:
bundle install --system
This will install the gems in the Gemfile system-wide, and will ask for the root password if you do not have access to the system folder.
--system:
Installs the gems in the bundle to the system location. This overrides any previous remembered use of --path.
You can also name your Gemfile(s), if you want to organize them in some way:
bundle install --system --gemfile=/path/to/my_special_gemfile
Related Topics
Rails Console: Reload! Not Reflecting Changes in Model Files? What Could Be Possible Reason
Why Does Ruby'S 'Gets' Includes the Closing Newline
Nomethoderror When Trying to Invoke Helper Method from Rails Controller
Cannot Use Rvm-Installed Ruby With Sudo
Stop Devise from Clearing Session
How to Understand the Difference Between Class_Eval() and Instance_Eval()
Can't Install Ruby Rvm on Ubuntu 16.04 Due to Gpg Bug
Rails 2 to Rails 3:Using Link_To Instead of Link_To_Remote (Including Remote and Update)
Running Command Line Commands Within Ruby Script
How to Implement a Friendship Model in Rails 3 for a Social Networking Application
Invalid Active Developer Path on MAC Os X After Installing Ruby
Why Are Symbols in Ruby Not Thought of as a Type of Variable
Rails Object Relationships and Json Rendering
How to Use "Gets" and "Gets.Chomp" in Ruby
Why Do Two Strings Separated by Space Concatenate in Ruby
How to Get the Name of a Ruby Class
Cache Resources Exhausted Imagemagick
Extract Single String from HTML Using Ruby/Mechanize (And Nokogiri)