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:
- source "http://rubygems.org"
Now that bundle install is slow, I will download the gem file and run it:
- 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:
- source "http://rubygems.org"
-
- gem "rspec", "~> 2.7.0"
- gem "rake", "~> 0.9.2.2"
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:
- gem generate_index -d /path/to/your/gemfiles/
-
- cd /path/to/your/gemfiles/
-
- gem server
Modify the source of your Gemfile as follows:
Source "http: // 0.0.0.0: 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:
- 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.
Link:
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