Elaborate on the Bundle of the Ruby project and how to speed up the bundle install

Source: Internet
Author: User

People who have worked on Ruby projects may feel the same way. rubygems.org's access to China is too slow. Every time we install bundle, we have to wait for a long time, but when we download the corresponding gems file through a browser, the speed is refreshing... Why is this happening? Clearly, what we write in Gemfile is:

  1. source "http://rubygems.org" 

Now that bundle install is slow, I will download the gem file and run it:

  1. gem install /path/to/gems/***.gem 

The result shows that some gem files are installed quickly, and some bundle files are installed slowly. Why? How can we avoid such pain?


Well, I will introduce the ruby bundle mechanism in detail below.

First, let's talk about the Gemfile file. Gemfile is used to describe the plug-in bundle that your current ruby project depends on. For example, in the java Plug-in project, which of the following plug-ins will the current project depend on, the dependent plug-ins have different versions. For example, the following is the Gemfile content of a simple ruby project:

  1. source "http://rubygems.org" 
  3. gem "rspec", "~> 2.7.0" 
  4. gem "rake", "~>" 

The first line indicates the server that my bundle downloads

Lines 3rd and 4th indicate that my current project depends on the rspec plug-in and rake plug-in.

"~> 2.7.0 "indicates that the desired version is> = 2.7.0 and <= 2.8.0

Before running the call code, you must bundle install the corresponding plug-in bundle.


However, if you write Gemfile, you need to install the bundler plug-in. This can be done using the following command:

Gem install/path/to/gem/bundler-version.gem

Download the bundler gem file to local First)


Okay. After bundler is installed, You can execute bundle install.

However, running bundle install every time is slow and slow, which makes me unable to handle it. What should I do?

Download the plug-in to the local machine and then install the gem. If the plug-in is dependent, it is still very slow because it will automatically access the server to download the plug-in that needs to be dependent. Since I can download the required bundle from a local browser, can I directly use it locally? The answer is yes.

We can build a local gem mirror server, which is very simple.

First, download all the gem files, which are actually bundle files. Note that the dependency plug-in must also be prepared and put in a local directory. Then execute the following command in this directory:

  1. gem generate_index -d /path/to/your/gemfiles/ 
  3. cd /path/to/your/gemfiles/ 
  5. gem server 

Modify the source of your Gemfile as follows:

Source "http: // 8808"

Then run bundle install. The result must be exciting ~


Finally, we recommend that you add a. rvmrc file to each ruby project directory. This file is used to specify the ruby version used by your project, the bundle installation directory and the cache directory .. The content of rvmrc is only one sentence:

  1. rvm --create use ruby-1.9.2@myprojectname 

Then, every time you enter the project directory, you will see the ruby prompt that will automatically switch to the corresponding version.

Note: After setting it for the first time, you need to reinstall the bunddler and bundle install.


In addition, every time you modify Gemfile, you need to install the bundle. At this time, not all bundle will be installed, because a Gemfile will be generated during the last bundle install. the lock file tells the bundle of the bundler that has been installed, and the dependency is also known. Only the newly added bundle will be installed this time.



1. Creating a RubyGems Mirror With HTTP Basic Authentication

2. Creating your own RubyGem mirror

3. Bundler description

This article from "enjoy programming life" blog, please be sure to keep this source http://huihua.blog.51cto.com/3865128/706748

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.