r15
r15

Reputation: 496

Store and install ruby gems locally for ruby project

I am currently working on sample ruby project (not rails). In the rails project we can use bundle package command for storing installed ruby gems.

It will lock and cache gems from RubyGems into ./vendor/cache. folder.

Now I have to use same functionality. So how can I store gems on local machine and when we do bundle install it will fetch the required ruby gems from that source.

Upvotes: 0

Views: 1521

Answers (2)

gateblues
gateblues

Reputation: 816

Use Bundler

install bundler from your server prompt (regardless of project folder) to ensure the bundle command is accessible.

gem install bundler

now that your server has bundler installed make a file under the root of your project called Gemfile and add the source and required gems something similar to:

source 'https://rubygems.org'
gem 'example_gem'
gem 'example_gem_with_version', ">=0.9.2"
...

Now your Gemfile is ready. From the root of your project run the bundle install command and specify your vendor directory

bundle install --path vendor

After it retrieves the source it will cache it under the vendor directory. To install locally without fetching from rubygems.org simply use

bundle install --local

Upvotes: 1

Peter Sorowka
Peter Sorowka

Reputation: 1036

bundler is not part of rails, but it is an independent ruby gem itself. so given you have the bundle command available, you can just set up you Gemfile and use bundle install as you are used to.

This is also described on the bundler homepage

Upvotes: 1

Related Questions