20--bundle and Gemfile

Source: Internet
Author: User

In this lesson we explain how bundles are built and how gemfile are used. Before we were just two words of code, this lesson we further to explain:

What's the matter, bundler?

is a management tool for managing gem-dependent packages in a rails application. It automatically downloads and installs the corresponding gem suite based on the settings in Gemfile and helps us to resolve dependencies between different packages. At the same time it can make the program in different deployment environment to use all the dependent package version can be consistent (because gemfile within the limits, different environments but are based on the same gemfile file), This will be ported to other computers or co-developed by others as long as they are consistent according to the same gemfile.

Bundler's role is to ensure that the gem packages installed in any environment are the same version based on the Gemfile settings.

RAILS3 version If you want to add any gem packages you have to explicitly write them in Gemfile, unlike earlier versions that can use require keywords to introduce gem packages. We are now using the RAILS4 version, unified use of gemfile for unified management is significantly more convenient,

The following code for the Gemfile file indicates that the GEM package is used only in the development mode and test mode, and if you want to use this gem package in a production environment, you can add the production in the same way after the group keyword.

The following is the only development mode to use the GEM package

?

We recommend that the Gemfile version number is better to write dead, for example, the bad also want to use the wave number (this way to ensure that the large version number is unchanged), so what is the benefit of writing? To minimize the risk of potential compatibility due to GEM package upgrades, because Ruby and rails are open source updates fast, so not writing the version to death is likely to escalate to a new version that you are unfamiliar with, leading to compatibility issues.

For example, there are three parts of the version number separated by dots, the first version number 4 changes indicate that the non-compatible changes occur, this is the X version number. If the second version number 1 changes indicates that there is a new feature increase, this is the Y version number. If the third version number 0 changes, indicating some bug fixes, this is the z version number. So you are the most incompetent also use ~> to ensure normal use (large version number is unchanged, the most is the z version number change is to fix some bugs).

As for the >=, avoid use.

This ensures that a large project has some upgrade resiliency and does not upgrade too much to cause incompatible errors.

?

If you modify the Gemfile file , such as adding a new gem package declaration code, or modifying a version of an existing GEM package declaration, then you need to use a command called bundle install to install all of our gem packages, This command checks and installs these gem packages to generate a Gemfile.lock file. The Gemfile.lock file lists the specific version of the Gem suite used by the current project, so be aware that if you use a tool like git to develop a project in sync, you must remember to push the Gemfile.lock file along with the commit or push, so that other on-line development Will install the library file specified in the Gemfile.lock for the purpose of maintaining the consistency of developing the gem version for many people.

The next command to be told is that the bundle update is followed by the name of the gem package (not gem_name), such as rails, to update the corresponding GEM package version.

Just after the bundle update has no GEM package name, it is the default to update all the gem packages to the latest version. (Do not use the bundle Update command unless it is necessary, otherwise the probability of incompatibility is very high because too many gem packages are updated at once). So if you want to upgrade the Gem pack, we'll just add the name of the gem package that needs to be upgraded, just upgrade one at a time.

?

In short, if a gem package changes, then generally we bundle install a command to be able to complete. If this command fails to install the Gem package during execution, interrupting the installation (which is very common), then you will need to use the Gem command to install the gem packages that cannot be installed separately and to resolve the possible errors based on the prompt information.

?

So how do we know which gem packages can be upgraded in our project? That's very simple, we can use commands, that is, obsolete commands this command will list all new versions, upgradeable gems as follows we found that Arel has installed the version is 6.0.3, the latest version is 7.0.0, if you want to upgrade, you can choose to upgrade it.

There are many commands for bundles, in fact the most used is the Bundle install command (the equivalent of a button to fix the buttons)

?

20--bundle and Gemfile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.