User:Jitendra92/Bundler
Original author(s) | Yehuda Katz,Carl Lerche |
---|---|
Developer(s) | Bundler Core Team |
Initial release | 29 August 2010[1] |
Stable release | 1.10.6
/ July 22, 2015[1] |
Written in | Ruby |
Operating system | Cross-platform |
Type | Application-level package manager |
License | MIT License |
Website | bundler |
Bundler is an application-level gem dependency manager for Ruby[2] written under MIT License. Ruby applications like any other software application have dependencies on other Ruby libraries and frameworks called gems to use certain features. Before an application can start using features from other gems, it needs to install those gems through a package manager like RubyGems which allows gems to be manually installed for the application one by one.
Bundler automates the installation process by tracking and installing the exact gems your application needs together with the required versions of their dependencies. It not only helps in installation of gems but also manages them throughout their lifecycle[2].
Additionally, Bundler checks the compatibility between the specified gem versions along with their dependencies before installing them. It also allows updating one or more gems to newer versions when they are available. By tracking and locking the versions of all gems and their dependencies, it allows application programmers to run the same ruby code on every machine ensuring easy code distribution.[3]
History of Dependency Management in Ruby
[edit]Require method
[edit]One of the oldest ways in Ruby to share code is the require method. It dates back to the year 1997 [4]. Require method takes in a filename, and loads that file exactly once. The require method makes use of the two important globals $LOADED_FEATURES and $LOAD_PATHS [5]. Working of require method can be logically represented through the following code snippet.
#Logical interpretation of LOADED_FEATURES
$LOADED_FEATURES = []
def require(filename)
return true if $LOADED_FEATURES.include?(filename)
eval File.read(filename)
$LOADED_FEATURES << filename
end
$LOADED_FEATURES maintains the list of all the files that have been ‘required’ once. So that the same code doesn’t run twice if require method gets called again. [6] To solve the problem of code being distributed in multiple directories and to provide absolute paths for the files in require method, global $LOAD_PATH is needed. This can be thought of as a list of directories to look into once require method is called. [4]
#Logical interpretation of LOADED_FEATURES
$LOAD_PATH = []
def require(filename)
full_path = $LOAD_PATH.find do |path|
File.exist?(File.join(path, filename))
end
eval File.read(full_path)
end
Setup.rb and The Ruby Application Archive
[edit]Setup.rb and Ruby Application Archive (RAA) combination for sharing code became popular with Ruby developers from the year 2004 [4]. At its core, setup.rb is a Ruby implementation of a set of three commands ( ruby setup.rb config, ruby setup.rb setup and ruby setup.rb install ) to install libraries [7].A developer had to browse through RAA looking for library and the version he needed, download the .tar.gz file containing the library, decompress the tar, and from the directory run ruby setup.rb. For updating the library same process had to be repeated as getting a new library. This did not support multiple version install so it created a problem if two applications running on a same environment needed different library versions.[4] RAA was shut down on August 4, 2013 due to lack of resources [8]. Setup.rb still exists but the code has not been maintained since the year 2005. [4].
RubyGems
[edit]In 2004 RubyGems came into existence.[9] Developers could now install and list gems through single commands like gem list and gem install[10]. Also it solved the existing problem by introducing installation of multiple gem versions. It provided its own patches to the require method. If no version of a gem was installed, it installs the newest version available. Developers could now call require for different versions of gem. This revolutionized code sharing in Ruby, and many libraries came up. But with increasing number of gems and their versions, managing dependencies became tougher. Every platform where the application is running had to install the same version of gem, which could create dependency problem for some other application running on the same server.[11] Many solutions like config.gem and gem_installer came up but they failed because RubyGems would simply install the newest available version. Gem activation errors where RubyGems was asked to install a version of the gem and then later on asks to install another version also became very common.[4]
Bundler
[edit]The problem with RubyGems was dependency resolution at runtime [4]. Developers had to manually figure out a set of gem versions which would work together before the application runs, this is commonly known as dependency graph resolution problem. Bundler automates this process. Bundler tries various combinations of versions before one combination works. Over the years, it has developed various heuristics to figure out which combination to try first. With this dependency resolution, it has become very fast and takes few seconds for most of the Gemfiles.[4]
Important Files
[edit]Gemfile
[edit]This file is used to specify a list of all the gems (dependencies) with their versions (optional) which the application requires Bundler to install and manage.
#An example of Gemfile
source 'https://rubygems.org'
gem 'rails', '4.1.0.rc2'
gem 'rack-cache'
gem 'nokogiri', '~> 1.6.1'
In the above shown example Gemfile[12], the first line defines the source which bundler will be using to fetch the listed gems in this file. The following lines declare the list of gems with their versions (optional)
Gemfile.lock
[edit]The file snapshots the exact versions of all the gems installed by Bundler. It not only includes the gems present in the Gemfile but also their dependencies. This allows Bundler to install all the dependencies of the application with their exact versions defined in this file on another machine instead of performing dependency resolution using the Gemfile. This file is automatically generated by bundler after a bundle install.[12]
Getting started
[edit]- Open the terminal and install bundler gem using the command
$ gem install bundler
- List the gems required by the application in Gemfile
#How to specify gems and their specific version in a gemfile gem "rails", "~> 4.0.10" gem "pg" gem "delayed_job_active_record" gem "devise", "~> 3.1.2" gem "figaro", github: "laserlemon/figaro" gem "will_paginate" gem "bootstrap-will_paginate" gem "simple_form" gem "honeybadger" gem "draper" gem "stripe"
- You may include gem version in the file if you need a specific one. [13]
- Install the listed gems and their dependencies using command
$ bundle install
- If Gemfile.lock is not present and bundle install is run for the first time, all remote sources are fetched, dependencies are resolved and all needed gems are installed.
- If Gemfile.lock is present bundler will use all gem versions specified in Gemfile.lock instead of resolving dependencies. In case Gemfile is updated, bundler will re-resolve dependencies for updated gems and use versions from Gemfile.lock for gems which were not updated. [14]
- Checkin Gemfile.lock to your repository so that other developers of the application use same version of the third party code. [15]
Primary Commands
[edit]Command | Description |
---|---|
bundle install | Install gems listed in your Gemfile and resolve dependencies [14] |
bundle update | Updates the version of the specified gem, updates all dependencies otherwise [16] |
bundle package | Copies all .gem files needed by the application to vendor/cache directory [17] |
bundle exec | Execute the specified command in context of the bundled gems in Gemfile [18] |
bundle config | To set various bundler configuration options [19] |
bundle help | Displays help for all subcommands [20] |
Supported Frameworks
[edit]Version History
[edit]Version | Date |
---|---|
1.10.0 [21] | May 28, 2015 |
1.9.0 [22] | March 20, 2015 |
1.8.0 [23] | February 10, 2015 |
1.7.0 [24] | August 14, 2014 |
1.6.0 [25] | March 28, 2014 |
1.5.0 [26] | December 26, 2013 |
1.3.0 [27] | February 25, 2013 |
1.2.0 [28] | August 30, 2012 |
1.1.0 [29] | March 7, 2012 |
1.0.0 [30] | August 29, 2010 |
0.9.0 | February 3, 2010 |
0.8.0 | January 4, 2010 |
0.7.0 | November 5, 2009 |
0.6.0 | September 23, 2009 |
0.5.0 | September 3, 2009 |
0.4.0 | August 18, 2009 |
0.3.0 | July 29, 2009 [1] |
References
[edit]- ^ a b c "Version History". Rubygems.org. Retrieved 13 September 2015.
- ^ a b "What is Bundler?". About.com. Retrieved 13 September 2015.
- ^ "Project Readme". Github. Retrieved 13 September 2015.
- ^ a b c d e f g h Cite error: The named reference
name="History-ruby-dependency-management"
was invoked but never defined (see the help page). - ^ "magazine.rubyist.net". Retrieved 16 September 2015.
- ^ "History of ruby dependency management". Retrieved 16 September 2015.
- ^ "Setup.rb usage". Retrieved 16 September 2015.
- ^ "RAA retires". Retrieved 16 September 2015.
- ^ "RubyGems Initial Release". Rubygems.org. Retrieved 17 September 2015.
- ^ "RubyGems Basics". Rubygems.org. Retrieved 16 September 2015.
- ^ "RubyGems good practices". Retrieved 16 September 2015.
- ^ a b "Gemfile Example". bundler.io. Retrieved 13 September 2015.
- ^ "How to write a gem file". Retrieved 14 September 2015.
- ^ a b "bundle install". bundler.io. Retrieved 13 September 2015.
- ^ "Getting Started". bundler.io. Retrieved 13 September 2015.
- ^ "bundle update". bundler.io. Retrieved 13 September 2015.
- ^ "bundle package". bundler.io. Retrieved 13 September 2015.
- ^ "bundle exec". bundler.io. Retrieved 13 September 2015.
- ^ "bundle config". bundler.io. Retrieved 13 September 2015.
- ^ "bundler primary commands". bundler.io. Retrieved 13 September 2015.
- ^ "Version 1.10.0 released". bundler.io. Retrieved 14 September 2015.
- ^ "Hello, Bundler 1.9!". bundler.io. Retrieved 14 September 2015.
- ^ "Git hub CHANGELOG.md 1.8.0". Github. Retrieved 14 September 2015.
- ^ "Github CHANGELOG.md 1.7.0". Github. Retrieved 14 September 2015.
- ^ "Github CHANGELOG.md 1.6.0". Github. Retrieved 14 September 2015.
- ^ "Githib CHANGELOG.md 1.5.0". Github. Retrieved 14 September 2015.
- ^ "Github CHANGELOG.md 1.3.0". Github. Retrieved 14 September 2015.
- ^ "Github CHANGELOG.md 1.2.0". Github. Retrieved 14 September 2015.
- ^ "Github CHANGELOG.md 1.1.0". Github. Retrieved 14 September 2015.
- ^ "Github CHANGELOG.md 1.0.0". Github. Retrieved 14 September 2015.
Category:Free computer libraries Category:Free software programmed in Ruby Category:Software using the MIT license Category:Free package management systems