A quick tip to speed up bundle installs
Use more computing power to install gems faster
Here is a quick tip for speeding up how bundler installs gems on your computer.
Run the following command in your terminal.
bundle config set jobs $(nproc)
$(nproc)
will first call nproc
which returns the number of available processors. In my case 4. bundle config set jobs X
will tell bundle to install gems in parallel up to the number you pass in.
So in my case, if I run bundle config set jobs 4
, it will use all four processors the next time I use bundle install
. Depending on the size of your project, this will speed up your gem installs.
Looking at the code that handles this, it seems like without config it should try and figure out the number of processors and use that number. Yet when I try and run it, I get different results.
bundle config set
will store settings in a global file, which all projects use. We can test this by setting bundle config set jobs 5
in one project, going into another and starting an irb session.
require 'bundler'
=> true
Bundler.settings[:jobs]
=> 5
Bundler.settings
=> #<Bundler::Settings:0x00007fd8a39fea10 @root=#<Pathname:/Users/tosbourn/Projects/anotherProject/.bundle>, @local_config={}, @global_config={"BUNDLE_JOBS"=>"5"}, @temporary={}>
Note the @global_config
.
The global config is in your home directory. Running cat ~/.bundle/config
in my terminal gives me:
BUNDLE_JOBS: "5"
A lot of work done during gem installs relies on the network. It is worth experimenting with larger numbers than the result of nproc
. You can always remove the setting again if you don’t like it bundle config unset jobs
.
Finally, it might be useful to think about other places that could benefit from this. Such as your continuous integration setup. If you are running bundle install
you should pass in the number of jobs to use as a flag bundle install --jobs=8
.
If you want to learn more about gemfiles, read our article; what is a gemfile.