Copy vendor/cache gems - ruby-on-rails

I have a set of old gems I can't install from internet.
My plan is to copy what is in production server to my local environment.
gem env to know where gems are being installed.
cd to_gems_dir
there are a of of folders there,
I copied cache folder to my local machine
under vendor/cache inside project folder.
run bundle to check everything is OK.
But is not, bundler tries to install some gems, some others not. I don't know too much about bundler and gems envs, so my question is what am I doing wrong here? any other ideas to replicate remote gem set in my local machine?

This is what I did:
for file in vendor/cache/*; do gem i --local $file; done
Then all gems where installed, finally:
bundle check
The Gemfile's dependencies are satisfied

Related

Bundle - copy-paste gems from another PC

I am trying to setup a rails application. The application depends on an enormously huge number of gems. The gems were preinstalled in the vendor/gems folder of a copy I obtained from a friend. Now, considering the unavailability of those closed source gems, bundle install --path /home/umang/projectname/vendor/gems fails with the message Could not find gemname in any of the sources. Is there a way I could copy-paste the gems from the vendor/gems/ folder into my gem installation directory and make bundle believe that they are there. I copied the directory from vendor/gems to my local gem installation directory, but bundle check still suggests that those gems are missing.
Okay, it is time I answer my own question.
1. Copy-paste the gems to your gem installation directory.
2. Remove the .bundle/config or fix the conflicting setting.

Deploy ROR application to a machine without internet access

I complete a simple Ror hello world application. The problem for me now is how i can deploy it another Window machine which is physically off to the Internet. I can copy files and application by USB. But how can i install gem to that machine? Does anyone have similar experience?
You can do bundle package to package the gems (in a machine with internet) and copy over.
You can then install local gems using bundler:
bundle install --local
Not that you could get bundle gem itself by doing:
gem install --local bundle.gem
where bundle.gem is obtained using gem fetch bundler.
If you're talking about your application's dependencies, take a look at the bundle package command, which will download all of the dependencies to ./vendor/cache. You can then copy the vendor along with your application and Bundler will it instead of fetching the gems off the internet.

Gem from github in a different directory

Hi im a bit astonished,
why sometimes a gem (installed with bundle install) isn't stored in the Project/vendor folder, but instead in ~/.rvm/gems/ruby-1.9.3-p484/bundler/gems folder.
This issues that, assets from this gem are not getting precompiled.
Is there a decent ways for handling this.
Run bundle install --path specify_path_that_you_want
so it will always install all of your gems in that your specified directory.

Bundle install tries to use cache file

When i try to do bundle install, my gem_path and gem_home point to /usr/local/rvm/gems/ which i don't have write access and it fails because of invalid permissions. because of this i've changed both paths to a local directory where i do have write access.
when doing so, i do a bundle install, i get :
bruno#test6:~$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Bundler::GemspecError: Could not read gem at /afs/varda.io/user/b/br/bruno/test6/cache/rake-10.1.0.gem. It may be corrupted.
An error occurred while installing rake (10.1.0), and Bundler cannot continue.
Make sure that `gem install rake -v '10.1.0'` succeeds before bundling.
well, if i do a gem install, it works just fine.
but bundle would just not work; even if a try to delete the cache folder that it complains about.
i did try "bundle install --no-cache" and it fails in the same way. (bundle install --deployment works fine too) how do i get bundle install to work ?
i've spent quite a bit of time, if anyone would have any guidance , i would really appreciate it!
Fixed it by deleting cache file and re-running bundle install.
rm -rf <location_of_cache>. In your case:
rm -rf /afs/varda.io/user/b/br/bruno/test6/cache
okay, first of all, you could solve all this issues easily by using rvm (user installation), see http://rvm.io, if that is not an option, you could try using project-specific gem paths.
for example i have the following bundler config file (~/.bundle/config)
---
BUNDLE_PATH: .bundle
BUNDLE_DISABLE_SHARED_GEMS: "1"
which causes bundler to install all gems in a .bundle sub directory (inside your project folder, where you run bundle install). now, if you remember to use bundle exec for your bins (e.g. cap(istrano)), you're fine.
if you somehow f*cked up your bundler / cache, try deleting the .bundle folder (in your project folder)
rvm reinstall all worked for me.
Before you do that, I would try
gem update --system
gem pristine --all --no-extensions
please note that rvm reinstall all takes a lot of time to complete...
If it's feasible, I recommend installing your own copy of rvm in ~/.rvm so you aren't tied to the system one. Trying to have a hybrid system+user approach will likely lead to more headaches later on.
Or, if you're open to alternate solutions, rbenv is a leaner & cleaner ruby manager.
Try to tell to bundler which folder it must use, something like bundle install --path <myfolder> or bundle install --path gems.
Note that I didn't test this yet, but it seems promising, please post the result for us.

How does bundler work (in general)?

I'm pretty new to Ruby/Rails but I was taking a look at bundler and was wondering how it works exactly. Do you install a full set of gems like normal gem install XYZand then use the Gemfile to pull a certain subset of those gems for use with a specific application? Or do you not install gems normally anymore and just include them in the Gemfile and then do a bundle install to include them all in a bundle that is then used with your application?
Thank you so much for taking the time to answer this, I'm just a little confused on what bundler's functionality is exactly.
-- MAP
These two links explain everything about bundler.
How does bundler bundle
How does bundle require gems
Think of bundler as a package management tool.
From bundle help command:
bundle install # Install the current environment to the system
bundle package # Locks and then caches all of the gems into vendor/cache
So bundle install command will install all gems to the system that are listed in Gemfile as well as their dependencies. If the gem was not previously installed it will grab it from the gemcutter repo. bundle package will cache the .gem files into your apps vendor/cache directory.
No need to run gem install first.

Resources