Quick question about gem installation — when I use bundle install I know it installs the gems necessary for my individual project, but it doesn’t affect other projects on my computer. If I use gem install name_of_gem would that also only affect the current project or would it affect all projects on my computer using rails (a generic installation)? In general I think I am a little confused about how exactly gem installation works, so if your answer could include some general background information to help me understand this that would be great!
Quick question about gem installation — when I use bundle install I know it
Share
Yes, gems are typically installed system-wide, or in your home directory is this is not possible. By default, when your application uses a gem, RubyGems loads the latest installed version. If you want to use a specific version, RubyGems lets you do that with this syntax:
Bundler is a helpful tool that tracks the versions of a gem that are being used to develop a project, and then allows you to both install them in one fell swoop with
bundle install, and also to load those exact versions. The application loads them by loading the Bundler code, which overrides parts of RubyGems to use the versions specified in the Gemfile.By default, Bundler just calls RubyGems to install gems (again, system-wide or in your homedir). You can ask it to store the gems in a directory called
vendor/cacheby usingbundle package. This lets you “freeze” the gems so that you can distribute them with the source code.If you want further isolation of your Ruby environments, you should use RVM, which lets you set up isolated gemsets, and in fact, different versions of Ruby, to use on different projects. When you’re using RVM, the directory where RubyGems installs things is overridden and is specific to your current Ruby version and gemset.
I’d recommend reading the docs for both RubyGems and Bundler; they’re both quite good.