Does 'bundle install' install all the requ

2019-07-21 13:06发布

问题:

I am new to rails and am learning about bundler. I understand that bundle install installs all the gems specified in the gemfile but where does it install them to?

Does it install them on my computer permanently so that they can be used by any future project?

If so doesnt this mean my computer gets filled with random gem versions and gem installs that I needed for one example project but may never use again?

回答1:

By default, bundle install is going to install at the root level so all users on a computer could have access to the gems. So 'yes' it is permanent (at least not tied to your application, you can remove them whenever you want).

Take a look at the man pages for bundler. In here, you'll notice that you can specify to install to a local directory.

Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem repository. In this case, install them to vendor/bundle.

$ bundle install --path vendor/bundle

Further bundle commands or calls to Bundler.setup or Bundler.require will remember this location.

This will let you install the gems to a location inside your application. So when you delete the example app, you also delete the associated gems.

Also, if you would like to see where a specific gem is installed (say you want to look at its source code), type bundle show <gemname>. This will spit out the path to that gem.



回答2:

The short answer is 'yes'. The longer answer is that there are some technologies which will reduce or eliminate the problems associated with this effect.

If you install 'RVM':

https://rvm.io/

this will allow you to install multiple versions of Ruby and create individual 'gemsets'. As you enter the directory that contains your project, the ruby version and gemset settings are automatically picked up and the active Ruby version will change. This way you can keep gems separate between projects - and use several Ruby versions at once, including JRuby and other esoteric versions.

To find out where gems are stored, type:

gem environment

into your command line and look for the INSTALLATION_DIRECTORY entry in the response.