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
Related
I'm new to web development and as I research how to install various dev tools on my Mac the following questions have come up,
Should I install Heroku via the standalone toolbelt or via homebrew?
Isn't the point of homebrew to manage non-Apple packages in a single place.
Ruby development using the bundler gem again seems like a wise decision, so that gems are no longer installed via gem install but rather with a project Gemfile. This would suggest that the only gem install required is Bundler. However, then I see developers install a range of tools like this
gem install bundler foreman pg rails thin --no-rdoc --no-ri
Is this just laziness or is there some reasoning behind this choice that I don't understand?
bundler and foreman I understand being outside of the project. Bundler for obvious reasons, and foreman because sometimes it doesn't like to run in the constraints of the bundle very well, but to my knowledge there is no reason to install pg, rails, and thin outside the bundle.
In certain bundler configurations, bundler will check for locally installed gems and use them as part of the bundle, while in others, it does not. Perhaps the reason for installing that suite of gems is to prevent multiple versions of the gem being installed in different projects on the system, essentially acting as a global repository of gems.
In all honesty, I'm brainstorming on this one, but its the only logical explanation I can come up with, hopefully someone can answer this better than myself.
I updates my gems, now I get this error:
Unable to activate capybara-mechanize-0.2.7, because capybara-1.1.1 conflicts with capybara (~> 0.4.0) (Gem::LoadError)
I've googled and searched SO, but I'm a bit of a n00b and not really sure what I need to do next.
Thanks for your time,
Mike
You can try to delete conflicting gem by invoking gem uninstall capybara. You will be the prompted which version to delete.
To remove all old gems in one swipe just use gem cleanup.
After cleaning old version which, hopefully, you don't need you should be ok. Otherwise, consider using bundler (http://gembundler.com/) to manage gems in your projects and RVM, where you can have completely separate gemsets.
My general workflow is as follows:
In Rails/Sinatra etc applications I put vendor/cache in my .gitignore and run bundle pack which installs gems into that directory. That way I can keep installed gems local per application.
In my daily workflow I use RVM to switch ruby versions and install gems into gemsets which I can port across RVM rubies. http://beginrescuened.com. A popular and more lightweight alternative to RVM is https://github.com/sstephenson/rbenv.
So bundler manages my gem dependencies in a sane manner and RVM lets me manage gems at a granular level. I went through the dependency hell of plain old rubygems a while back, never again.
You've either got two versions of Capybara installed (both 1.1.1 and some other version). You can go a gem list --local (or if you're using Bundler do a bundle show) and uninstall one of them.
Or possibly you've specified that you want versions ~> 0.4.0, and the version number 1.1.1 is out of that range. That is, the specified version range ~> 0.4.0 will only work with 0.4.0 .. 0.4.x, and not 0.5.x or higher.
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.
I am trying to install sproutcore on a windows xp vm (virtualbox), for development, using RubyGems. When gems reaches haml-3.0.25.gem it stops with the error:
gem install sproutcore -V
...
ERROR: While executing gem ... (Zlib::DataError)
invalid stored block lengths
I have tried both Ruby 1.8.7 and 1.9.2 as well as RubyGems 1.7.1 and 1.8.1.
I tried downloading haml 3.1.1 with git and installing it manually, but the rake would not install. It said something about 'lib/haml' not found. The directory did exist.
Other gems install just fine under all the combinations I tried. I even tried installing it under my host OS (Win 7 32-bit), but it gave the same error. Installing haml by itself changes the error message only slightly:
gem install haml -V
...
ERROR: While executing gem ... (Zlib::DataError)
invalid code lengths set
Zlib compresses and decompresses data streams from what I have read, so it sounds like the haml gem might be corrupt (although I doubt).
I am at my wits end and could find no helpful advice anywhere.
Special thanks to #saner for his contribution. After a lot of frustration, this is how I finally installed sproutcore on a Windows XP VM running on a Windows 7 host.
1) Download and install Ruby 1.9.2-p180 (remember to tick the option to include the bin directory in the PATH variable).
2) Download DevKit 4.5.1 and extract it.
3) Open a command prompt and cd to the extracted directory.
4) Run:
ruby dk.rb init
ruby dk.rb review
ruby dk.rb install
5) Download RubyGems 1.7.2 and run setup.rb
6) From the command prompt run
gem install haml -v 3.0.24
gem install eventmachine --pre
gem install sproutcore --pre
Thats it.
Enjoy.
I was able to install SproutCore on Ruby 1.9.2:
Install Ruby 1.9.2-p180
gem install sproutcore --pre
gem install eventmachine --pre
gem uninstall thin
gem install mongrel
I needed to remove thin because starting sc-server ended with errors, SproutCore will use mongrel instead of thin.
Update:
I didn't mention that I use RubyGems 1.7.2 and I have installed DevKit and Cygwin.
I removed all versions of SproutCore, Mongrel and Haml, then I typed:
gem install sproutcore --pre, SproutCore v1.6.0.beta.1 was installed.
eventmachine --pre, eventmachine (1.0.0.beta.3 x86-mingw32) was installed
SproutCore works with this setup, using mongrel was not necessary.
My configuration: sproutcore (1.6.0.beta.1), ruby 1.9.2p180, gem 1.7.2, thin (1.2.11 x86-mingw32), eventmachine (1.0.0.beta.3 x86-mingw32), haml (3.0.25), gcc version 4.5.0 (GCC)
I know this is a really old question, but since I just experienced the same problem, I've decided to add my insights on it.
So, it happened while I was trying to install the same set of gems on two different machines with different architectures, with different locations and respectively in different networks. I.e. - my home mac and a remote linux server.
So, one particular gem (dm-sqlite-adapter) failed installing on both machines, and I even tried it couple of times, but always with the same result:
$ gem install dm-sqlite-adapter
ERROR: While executing gem ... (Zlib::DataError)
invalid code lengths set
Then I spent few minutes browsing the network for a solution, including reading this thread.
Since I didn't find any satisfying answer and I wasn't pleased with the idea of reinstalling everything, decided to act dumb and tried gem install one more time.. And it worked. Then tried the other machine - worked like a charm.
So as a conclusion I'd just guess that the problem came from the remote repo and maybe the gem hadn't even downloaded at all (I forgot to check that prior to succeeding installing it). But as I said - it's just a guess..
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.