Is there a way to update RubyGems offline? - ruby

I am trying to install Ruby + WATIR to a Windows server which is in an isolated environment. Typically I would run the ruby installer followed by these two commands:
1) gem update --system
2) gem install watir
This is as per the instuctions here
The server I am now trying to install to does not have internet connectivity. This causes the commands above to fail.
Is there a way I can download the update packages required and copy them to the server to install locally?

When you do gem install it will search the current directory before looking to the remote source. You must specify the version if you are installing a local gem (see rubygems manual).
gem install copland-0.2.0.gem
I'm sorry, I don't know a way to update the gem system offline without doing a manual upgrade

I usually use
gem unpack blah-1.1.1.gem
to unpack the gem into individual Ruby files. Then you just need to make sure that directory is in your Ruby load path, and it's as good as a normal gem.

Related

Install gem in local folder

I have limited privileges on a shared machine I'm using, so I can't install gems the way I'm used to. For example:
$ gem install request-log-analyzer
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
Is it possible to install a gem locally? (if it matters, I'm trying to install this gem.)
I saw a number of posts on Stack Overflow that talked about using Bundler or gemfiles but I'm not installing this gem for a Ruby on Rails project - I just want to use it in isolation.
I'm running Linux, not sure which flavor though.
You can try:
gem install --user-install gem_name
Add the --local flag to your install:
gem install --local request-log-analyzer
If that causes any problems, try downloading the gem manually and pointing gem directly to it using:
gem install --local path/to/gem/filename.gem
If you want to install it to your user home, as per rubygems:
When you use the --user-install option, RubyGems will install the gems
to a directory inside your home directory, something like
~/.gem/ruby/1.9.1. The commands provided by the gems you installed
will end up in ~/.gem/ruby/1.9.1/bin. For the programs installed there
to be available for you, you need to add ~/.gem/ruby/1.9.1/bin to your
PATH environment variable.
The command for this would just be
gem install --user-install request-log-analyzer
You could just use RVM: Ruby Version Manager. It is a complete version manager, along the lines of node version manager (nvm) and others, in that it allows you to have different versions of ruby and different collections of gems for each project. It does the job of keeping gems isolated from each other as well as from the system ruby, but at the expense of learning a complete version manager.
When run without root, it installs locally in ~/.rvm and doesn't affect other users.

Installing Sinatra and JSon for ruby

I want to install JSON and Sinatra on my Mac that does not have an internet connection.
How can I download and install Sinatra and JSON with all their dependency packages from another machine and then install on my Mac?
JSON is already installed on Ruby 1.9.2+. If you're not running that already you should be as Mac OS comes with 1.8.7, which is pretty old now, and has been deprecated.
You don't want to try to install a newer version of Ruby on top of Apple's version of Ruby, as they installed it for their own use. Something like rbenv or RVM would be the suggested ways of installing something newer. However, if you're not attached to the internet then you'll have a lot of work ahead of you.
Rubygems can tell us what gems another gem depends on:
gem depend sinatra
Returns:
Gem sinatra-1.4.3
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3.4, ~> 1.3)
Those are the gems you'd have to download and copy over, and install prior to installing Sinatra. Be aware that each of those dependencies probably have their own dependencies also, so you'll need to walk through the list to get everything necessary.
gem fetch sinatra
will retrieve the Sinatra gem to the local directory. Once that's done you can copy it somewhere else convenient. Do the same for the other files you need/want.
Rubygems can install a gem from a local archive. Type gem help install at the command-line for more information, or see "How can I install a local gem?" and "RubyGems Basics", in particular the "Fetching and Unpacking Gems" section for more information.
Honestly though, trying to do any development on a machine that isn't attached to the internet in some form is going to be very, very, painful. I consider an internet connection essential for my development work these days, and when I have to work on a machine that doesn't give me that at work I get pretty grumpy, even when the machine has network connections to other machines that are attached to the internet. That delay and extra step is a real pain.
You could use a networked machine and instruct bundler to install all required gems in a specific location.
$ bundle install --deployment
will install gems at vendor/cache, whereas
$ bundle install --path path/to/directory
will install gems at the given path. Please refer to the bundler documentation.
This will allow you to install everything on a thumb drive (or other portable storage device) and copy the entire directory to your Mac.
If you have more complex requirements, such as controlling ruby versions with rbenv, you can
get your setup right on a networked machine
create a disk image
use vagrant on your mac with the image

Installing gem-bundle for Redmine 2.1.4 with Ruby 1.9.3 (including rmagick 2.13.1) on Windows

I'm having problems installing json or rmagick gems on Windows, which I need because I am trying to install Redmine 2.1.4.
As none of the procedures worked out-of-the-box for me and have struggled with it myself for a couple of hours, I thought I'd just ask here for help.
I'm assuming you don't have Ruby installed yet. If you do, as any of other components mentioned below, probably it's the wisest to uninstall them before proceeding with installation.
This tutorial should help you avoid problems with json and rmagick gems on Windows.
First, download Redmine 2.1.4 from rubyforge as zip or from SVN or Git as described on the relevant Redmine Wiki page. rubyforge tends not to work, so you can be forced to use the latter.
Download RubyInstaller (1.9.3 at the time of this writing) and DevelopmentKit from rubyinstaller.org
Install Ruby using the downloaded installer. Use a directory without spaces in name, i.e. don't install it to Program Files. I checked the options as below
Open command line, check if Ruby path has been added to your system. ruby --version should show the version installed, 1.9.3 in my case. If you had command line opened while installing Ruby, close and reopen it to load path.
Extract DevKit to a path with no spaces. Change to DevKit's directory (might be e.g. under Ruby's installation, i.e. C:\Ruby193\DevKit). Execute the following:
ruby dk.rb init
ruby dk.rb review (should detect Ruby's installation path correctly)
ruby dk.rb install
Install bundler gem gem install bundler
Go to Redmine home directory. Execute bundle install. You will probably (if not yet fixed) get the rmagick error - don't worry yet.
Go get ImageMagick. I picked ImageMagick-6.8.0-7-Q16-windows-dll.exe. Install to a directory whose path doesn't include spaces, e.g. C:\ImageMagick. Choose to install header files as well, as below:
Add ImageMagick home to path. Close command line and reopen it. This will reload path.
Execute `gem install rmagick --platform=ruby -- --with-opt-lib=c:/ImageMagick/lib --with-opt-include=c:/ImageMagick/include
Go to Redmine home directory again. Execute bundle install again. Should work now.
Hope that helps!

Bundle Install not installing the gems from gemfile

I am trying to setup my rails application on Windows 7 machine. I installed Ruby 1.9.3 by using installer. I also installed Rails 3.2.2.
Now, I am trying to run bundle install from my application root directory. This command used to install all the required gems. However, when I am running in this new machine its not installing. I have to install all the gems manually one by one.
I know its bit strange but I am facing this for the first time..!!
Edit 1: Please refer below screen-shot.
Note: I have already installed few gems manually before posting here. The error related to DevKit that I am getting below has just came while I was tried to install json gem..
After Installing more gems manually:
If you read the error, it tells you that you need DevKit to install that gem on Windows. So install that and follow the instructions, then try again ;) After the json gem can be installed, it should install every other gem in the Gemfile.
(The json gem is a dependency from Rails)

Rails -- gem installation

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!
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:
require 'rubygems'
gem 'RedCloth', '3.0'
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/cache by using bundle 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.
When you do bundle install the gems are installed at rubygems and would be available for all your projects unless you're using RVM and setting up gemsets for your projects.
When you're not using RVM and you do a gem install your operating system is probably going to install the gem at your current user's files (usually ~/.gem), if you sudo install gem it's going to install wherever is the place your system Ruby is installed.
I would really recommend you to setup RVM do manage separate groups of gems and rubies. You can read their website linked above or a simple tutorial I wrote to use it.

Resources