bundle vs bundler / bundle vs bundle install - bundler

What is the difference between the bundle & bundler commands?
What is the difference between bundle & bundle install?
If there're no differences, why have multiple commands that do the same thing?

The executables bundle & bundler have the same functionality and therefore can be used interchangeably. You can see in the bundler/exe directory that the bundler executable just loads the bundle executable. It seems to me that the bundle command is more commonly used than the bundler command.
The commands bundle & bundle install also have the same functionality. bundle uses Thor, and bundle's default task is install. Also, bundle i does the same thing as bundle install because bundle's task i is mapped (aliased) to install.
That's a GREAT question. :-) Ruby tends to follow the Perl programming motto: "There's more than one way to do it." I tend to prefer the Zen of Python principle: "There should be one—and preferably only one—obvious way to do it." I think the latter principle caters to the principle of least astonishment and tends to help keep things simple. Overall however, I still tend to prefer to program in Ruby (especially when building HTTP-based RESTful APIs, for which I use Rack). I think Ruby is simple, elegant, and readable. Perhaps Ruby would be even better if it took on Python's stance regarding this issue.

Related

bundler vs RVM vs gems vs RubyGems vs gemsets vs system ruby [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am new to Ruby and trying to wrap my head around following concepts: bundler vs RVM vs gems vs RubyGems vs gemsets vs system rub and I'm confused.
Can someone please describe a 'best practice' of how I should manage all this on a fresh install of the latest version of Ubuntu? What should I install, and how should I use it all?
I'm guessing that doing a sudo apt-get install ruby is not be recommended, but I am not sure. I tried it on my system in addition to 'all the other Ruby stuff'. It's just adding to my confusion. I am not talking about Rails but just regular Ruby gems (e.g. Vagrant, Chef, scripts).
As per the previous answer, this is quite a lot to cover, so consider this a short introduction.
gems are the way Ruby libraries are packaged. They are to Ruby what jars are to Java. Inside a gem file, you find Ruby code (.rb files), but also tests, and a special file giving information on the gem itself, such as its name, dependencies and version (gemspec). Any Ruby project can define the gems it needs via a Gemfile that just need to declare dependencies. Rubygems is the name of the package manager - the tool used to install the packages (while the gems are the packages themselves). Rubygems is now part of Ruby.
Bundler is what makes managing gems bearable. Based on your Gemfile, a simple call to bundler using bundle install will download and install all the required gems. Using standard gem command, you would have to install each of them manually, using gem install <gem_name>. Bundler is not part of Ruby (it is itself packaged as a gem), but it a "de facto standard" for most applications (you will not find many people not using it, and no good reasons not to use it, actually).
RVM is a tool allowing you to install multiple versions of Ruby on a machine, switching between them when needed. This can be used to install both a Ruby 1.8 and 1.9, or even a "MRI" (Matz's Ruby, the default implementation) and alternatives (such as JRuby or Rubinius). Note that RVM is not alone in this field, see for instance rbenv.
A gemset in RVM is a set of gems specific to a given context, typically a project. This is useful if you are for example developing different applications, each with its own sets of gems, and want to keep them separate.
system Ruby is, when using RVM, the Ruby version installed on the machine (ie, not via RVM).
If you are just starting, gems and bundler are of interest to you. You can let RVM and gemsets aside for now.
You're asking for more information in one question than is in-scope for Stack Overflow. To cover it all would take a book.
On Ubuntu it's easy to install and remove gems to the "system" version of Ruby, so get used to installing and removing regular gems via sudo. (On Mac OS I'd give different advice because Apple bundles Ruby for their own use and it's not a great idea to mess with it.) Then, when you have an idea how the whole gem idea works, and you know you want multiple Ruby versions on your system, try "rbenv" or "RVM" and install a version or two in your sandbox.
Linux makes it easy to add/remove Ruby via a distribution, but we're limited to the versions the distro maintainers have packaged, so I usually install from source. But, that's a pain when managing several versions of Ruby for development, test and production systems, which is why rbenv and RVM were invented -- they handle the dirty detail allowing us to concentrate on programming.
I've used both rbenv and RVM, and have been using rbenv for the last six months or so, with good results. It's less complicated than RVM which I like. In either case they make it easy to have different versions installed, with separate sets of Gems. You can have different Ruby versions open in different terminal windows if you want, making it easy to test for compatibility.
Rule one when debugging is to make changes one at a time, which is true for learning to program or learning a new language. Don't be distracted, just keep it simple.

RubyGems plugin to tame a big ball of already-installed gems?

Maybe someone knows if this sort of RubyGems plugin exists already, before I try to sink a lot of time into writing one myself.
I'm not using RVM* or Bundler (edit: see thread in comments), so I have a big ball of system gems installed. I want to sort out which ones are gems I really want to use, which ones are dependencies that have to be there for the gems I really want to use, and which ones are just junk that can be cleaned up.
If anyone is familiar with Gentoo, I'm thinking of something similar to Gentoo's package management, but for RubyGems instead--a way to tag a small list of gems I really want to keep, then run a command that can go through all of my gems and clean up the ones that aren't dependencies of those gems. A "#world" set for RubyGems, in other words.
*RVM isn't an option for me anyway, because I have to use Microsoft Windows.
If you install graphviz, then you can runbundle viz this will produce a dot notation mapping of the dependencies and you can use that to trace dependencies down to those gem's you actually need to have installed (but only those that you have installed via bundler).
bundle viz --format=dot

Easy way to distribute ruby script

I have a bunch of ruby scripts in a folder which is added to $PATH and I think that some of them might be usefult to others. So I want to distribute them and the only 'good' way I know is rubygems (gem containing only binary), it has a very useful advantage of versioning, but also a drawback of initialization time (sometimes it takes some seconds before script starts to run). Are there alternatives?
Gem is good enought for this. I use gem for this purposes as it is very convenient to intall and update.
Gems are built for this. I'm not sure what you think a gem is, but RubyGems is a repository like PEAR for PHP, aptitude for ubuntu, or CPAN for perl, except they contain ruby libraries.
There is no extra overhead or "initialization time" added to your ruby libraries by making them gems. RubyGems simply installs your library - it doesn't do anything else.
Gems are fine for this kind of Ruby script.
To quickly generate a new gem, try out bundle gem.
To quickly distribute gems without using rubygems.org, and in a way that could work for private deployment, check out the idea for microgems.
If you still don't think you need to wrap these in gems, you can simply add the executable bit to your scripts, add shebang lines for ruby, and remove the .rb extension. Then share your script files with whoever wants them.

How to distribute a Ruby application with the required gems

I've developed a Ruby application (a small game), and I would like to 'distribute' it to other people.
However, I am not sure what to do about the required gems. If I just send my application to someone who have ruby installed, but not the required gems, I assume it will blow up. Can I package the gems locally? If so, would it conflict if the other person has a different version of the gem?
So, what is the smart/proper/good way of doing this?
The best way would probably be to just package your game as a gem as well, that way rubygems will take care of installing the dependencies. Here's the documentation explaining how to create your own gems.
If you'd rather not package your game as a gem, you could investigate the Bundler, which will be integrated into Rails 3.
In your environment.rb you can express your gem dependencies, eg.
config.gem "activemerchant", :lib => "active_merchant", :version => "1.4.1"
This isn't as automatic as gem dependencies, but it certainly usable. User must sudo rake gems:install to get your app to start.
If you're looking for a way to create OSX .dmg's and Windows Installers, there's a gem called releasy that will do all of that for you, and it is specifically tailored for releasing GUI apps written in Ruby. It bundles up Ruby and all your gem dependencies in to a single executable so that your end user doesn't have to install anything extra.
You will need access to a Windows/OSX environment to make the installers.

Ruby: just-in-time gem installation?

Would it be possible to override the default "require" by adding automatic download-and-install code for any missing includes (provided that the missing include is published as a ruby gem).
Which would not work in situations where Ruby is not interfaced with a shell. But still I think it would be an interesting idea.
Is there such a mechanism in existence today?
Edit:Removed portion about password check. I just checked and gem install doesn't seem to require me to type my password.
You would be able to hijack require method so as gems are installed when an attempt is made to require them, but still you won't have access to newly installed gem in current process, because gem index has to be reloaded.
I understand the intentions but I think exercise might not be worth it.
When installing a fresh gem the gem will be installed in the GEM_HOME. If that is not writable then it will try in the user's home .gem directory (on *NIX at least).
You could certainly script this. In a way Rail's rake gems:build is just this. Just not on demand.
But, I would recommend against this. You could run into build, versioning, dependency and network issues. And probably security issues as well.
PS: Francis Hwang did something related a while ago, although only as a require, not a require gems.
http://fhwang.net/2005/11/01/urirequire-I-got-yer-Web-2-0-right-here
A better option would be to use bundler and distribute the required gems with the application.
It is also quite simple to write a script to bootstrap the installation of gems if you didn't
want to distribute them with your code (using the bundle install/check commands)

Resources