Deploy ROR application to a machine without internet access - ruby-on-rails

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.

Related

rails offline installation in windows

I want to install ruby on rails in offline mode (i.e. without internet connection). So I downloaded railsinstaller-3.2.0.exe from http://railsinstaller.org/en and installed it. By the end, I had ruby installed but in order to have rails installed I ran
gem install rails
and faced these errors: (meaning command needs internet connection)
ERROR: Loading command: install (ArgumentError)
unknown encoding name - CP720
ERROR: While executing gem ... (NoMethodError)
undefined method 'invoke_with_build_args' for nil:NilClass
I mean is there any solution like downloading gems with another computer connected to internet and then copying files in the proper location in the installed directory of gems.
Please help me if you have any idea.
As said in a comment, it's a gem (lib) dependency issue.
You might want to look into installing the bundler gem library to manage dependencies for you, with bundler you would just have to run, bundle install and it would download all the required gems for you including any gem dependencies.
You can install bundler simply, just run
gem install bundler
Then in your rails project directory, just run bundle install.
Often to run a project (like rails for example) you might have to start it with
bundle exec rails start
To install Gem's on a non-internet connect computer you might want to refer to this answer on just that problem.
This is the website where you can find all available ruby gems. Ruby
gems download. Find the one you are interested and download it.
Then move the gem in a directory of your choice and cd into that from
the command prompt. I am using C:/ruby193/bin/pony-1.4.gem
Let's say that the gem we are interested in is the pony gem (smtp
email).
Just type gem install pony-1.4.gem
and you should get it installed manually unless you have a restricted
acc with not adequate administrative privileges.
You can also refer to the official documentation on the matter.

How do you package a ruby application for offline installation?

I have an intranet server with no internet access that I need to deploy a RoR application on it.
My process will be to download Ruby, install it, download Rails, install it, etc. But I have multiple gems in my Gemfile I'd like to install. How can I get these on the intranet server? Do I have to download them all separately, or is there there a way to package them up?
You can tell bundler to vendor all the gems needed for your app, by running:
bundle install --deployment
That will create a vendor directory in the root of your application. Make sure you include this directory when moving the app to the standalone server. You will still need to install Ruby, RubyGems, and the bundler gem.
For Ruby and RubyGems you can download their respective installers. You can download a copy of the bundler with gem fetch
gem fetch bundler
This will download a gem file like bundler-1.6.5.gem, which you can install on the standalone server with:
gem install bundler-1.6.5.gem

Install gems via ftp

Can you install your ruby gems via ftp? I mean just copy your local gem directory /var/lib/gems/1.9.1/gems and put it online with filezilla in the ruby>gems>gems directory.
The reason I want to do this is because with cPanel it gives me errors when trying to install some gems (like permission errors, some require ruby >=1.9.2 but I already have ruby 1.9.3). So is there a simple way?
Thanks!
Instead of copying your system's gem which may be ruby version specific, you could place all the required gems sources in your application's lib directory and reference them in your Gemfile. Not that you cannot place these sources in other directories.
Place gem source in your local application e.g. #{Rails.root}/lib/my_gem and update your Gemfile to reference the gem using:
gem "my_gem", path: "lib/my_gem"
Then run bundle install to install the sourced gem in your application.
and you can run
gem server
then add the source
http://some.ip:8808
there you'll have shared the gem installed in that system

Rails: purpose of downloading gems locally

Generally, if I need a gem, I put it in the Gemfile and bundle install. However, I don't understand if there is a benefit to downloading the gems locally first with gem install _____. Is there any benefit to this? Does bundle install no longer have to connect to the net in that situation?
Bundler installs the gems located in your Gemfile locally the same as if you ran gem install for each of those gems.
Gem install needed for gems that can be used outside of bundler applications. For example request-log-analyzer need to be installed outside of any apps for be available in command line.
I myself use gem install _______ then i use bundle install --local which doesn't require internet connection if the gem is found locally but will return an error if the gem was not found locally...
I find this method faster in downloading and installing gems, plus if the gems are found locally then i have also the benefit of altering the gemfile and install the gems without having internet connection.

Copy vendor/cache gems

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

Resources