# Ruby build error

**URL:** <https://discuss.circleci.com/t/ruby-build-error/11827>\
**Category:** Bug Reports\
**Tags:** ruby, rubygems\
**Created:** [April 10, 2017, 9:27pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827 "2017-04-10T21:27:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![diogoribeiro](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@diogoribeiro](https://discuss.circleci.com/u/diogoribeiro)\
**Post date:** [April 10, 2017, 9:27pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827/1 "2017-04-10T21:27:49Z")

</div>

All my builds are failing when circle ci tries to run  
bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3  
It gives me the following message error:

> An error occurred while installing eventmachine (1.2.3), and Bundler  
> cannot continue.  
> Make sure that `gem install eventmachine -v '1.2.3'` succeeds before  
> bundling.

To solve this I need to re-run the build without cache. Is there any other solution?

---

<div class="post-metadata">

**Author:** ![peteygao](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/peteygao/32/15898_2.png) [@peteygao](https://discuss.circleci.com/u/peteygao)\
**Post date:** [April 11, 2017, 10:49pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827/3 "2017-04-11T22:49:57Z")

</div>

This seems to be an entire class of similar issues. `bundle install` would fail non-deterministically for no particular reason.

When using `Debug via SSH` to SSH into the box, the same issue would occur, but repeatedly invoking `bundle install` _will_ eventually succeed with all gems installed… So the failure is random (sometimes it’s gem X, other times it’s gem Y that fails).

Seems like a platform issue, can a CircleCI rep comment on this?

---

<div class="post-metadata">

**Author:** ![rap1ds](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rap1ds/32/15899_2.png) [@rap1ds](https://discuss.circleci.com/u/rap1ds)\
**Post date:** [April 12, 2017, 6:02am UTC](https://discuss.circleci.com/t/ruby-build-error/11827/4 "2017-04-12T06:02:59Z")

</div>

Thanks @diogoribeiro! You saved my day!

Just recently, we started to see our Ruby builds failing with the exact same error message.

**Rebuild without cache** solved the issue as @diogoribeiro suggested.

Here’s the full error message:

```auto
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/ubuntu/sharetribe/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.14/ext/ffi_c
/opt/circleci/ruby/ruby-2.3.1/bin/ruby -r ./siteconf20170411-20269-nst4mf.rb
extconf.rb
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/stub_specification.rb:113:in
`initialize': No such file or directory @ rb_sysopen -
/home/ubuntu/sharetribe/vendor/bundle/ruby/2.3.0/specifications/hiredis-0.6.1.gemspec
(Errno::ENOENT)
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/stub_specification.rb:113:in
`open'
from

...

Gem files will remain installed in
/home/ubuntu/sharetribe/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.14 for inspection.
Results logged to
/home/ubuntu/sharetribe/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.14/gem_make.out

An error occurred while installing ffi (1.9.14), and Bundler cannot
continue.
Make sure that `gem install ffi -v '1.9.14'` succeeds before bundling.

bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 --without=development returned exit code 5

Action failed: bundle install

```

Here’s the link to the build: [https://circleci.com/gh/sharetribe/sharetribe/3180#tests/containers/1](https://circleci.com/gh/sharetribe/sharetribe/3180#tests/containers/1)

Just guessing, but since we are using Ubuntu 14.04, could this be related to the latest build image update: [Ubuntu 14.04 Build Image Update 201704-02](https://discuss.circleci.com/t/ubuntu-14-04-build-image-update-201704-02/11794) ?

---

<div class="post-metadata">

**Author:** ![kaikuchn](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kaikuchn/32/14384_2.png) [@kaikuchn](https://discuss.circleci.com/u/kaikuchn)\
**Post date:** [April 12, 2017, 8:45am UTC](https://discuss.circleci.com/t/ruby-build-error/11827/5 "2017-04-12T08:45:35Z")

</div>

Facing the same issue, any gem that has a native extension may randomly fail during bundle install when a cache is present. This happens for us with bundler version 1.14.6 and ruby 2.3.4 as well as bundler 1.13.6 with ruby 2.3.1.

Oh and it started exactly 5 days ago. Everything was fine on Thu Apr 6 17:44:31 2017 +0200 then every build would fail starting from Fri Apr 7 10:26:15 2017 +0200.

---

<div class="post-metadata">

**Author:** ![peteygao](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/peteygao/32/15898_2.png) [@peteygao](https://discuss.circleci.com/u/peteygao)\
**Post date:** [April 18, 2017, 9:21pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827/6 "2017-04-18T21:21:39Z")

</div>

This issue is still persisting, and `Rebuild without cache` is not a permanent fix–even after the cache has been cleared and rebuilt, the issue will rear its ugly head within a few days (or hours, depending on how frequently new builds are kicked off).

If any CircleCI Staff are actually reading this forum, it’d be nice to at least get an acknowledgement of the issue.

Here’s the full stack trace I encountered this time around (the native extension that fails to compile is non-deterministic).

```auto
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/ubuntu/underwrite/vendor/bundle/ruby/2.3.0/gems/stackprof-0.2.10/ext/stackprof
/opt/circleci/ruby/ruby-2.3.1/bin/ruby -r ./siteconf20170418-15913-1p4u4fv.rb
extconf.rb
Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem
pristine binding_of_caller --version 0.7.2
Ignoring byebug-5.0.0 because its extensions are not built. Try: gem pristine
byebug --version 5.0.0
Ignoring nokogiri-1.6.6.2 because its extensions are not built. Try: gem
pristine nokogiri --version 1.6.6.2
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/stub_specification.rb:148:in
`missing_extensions?': undefined method `missing_extensions?' for nil:NilClass
(NoMethodError)
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/basic_specification.rb:71:in
`contains_requirable_file?'
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/specification.rb:1037:in
`block in find_by_path'
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/specification.rb:1036:in
`each'
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/specification.rb:1036:in
`find'
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/specification.rb:1036:in
`find_by_path'
from /opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems.rb:189:in
`try_activate'
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:125:in
`rescue in require'
from
/opt/circleci/ruby/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in
`require'
	from <internal:gem_prelude>:6:in `<internal:gem_prelude>'

extconf failed, exit code 1

Gem files will remain installed in
/home/ubuntu/underwrite/vendor/bundle/ruby/2.3.0/gems/stackprof-0.2.10 for
inspection.
Results logged to
/home/ubuntu/underwrite/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/stackprof-0.2.10/gem_make.out

An error occurred while installing stackprof (0.2.10), and Bundler
cannot continue.
Make sure that `gem install stackprof -v '0.2.10'` succeeds before bundling.

bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 returned exit code 5

Action failed: bundle install

```

---

<div class="post-metadata">

**Author:** ![pean](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/pean/32/12764_2.png) [@pean](https://discuss.circleci.com/u/pean)\
**Post date:** [May 5, 2017, 7:47am UTC](https://discuss.circleci.com/t/ruby-build-error/11827/7 "2017-05-05T07:47:54Z")

</div>

I bumped into the same issue when trying to swith to Trusty image and Ruby 2.3.4 at the same time. Rebuidling without cache works but that as previously stated not a permanent solution.

Here the error I get:

````auto
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/ubuntu/kundportalen/vendor/bundle/ruby/2.3.0/gems/json-2.0.3/ext/json/ext/parser
/opt/circleci/ruby/ruby-2.3.4/bin/ruby -r ./siteconf20170505-18297-1eqsy1d.rb
extconf.rb
Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem
pristine binding_of_caller --version 0.7.2
Ignoring eventmachine-1.0.9.1 because its extensions are not built. Try: gem
pristine eventmachine --version 1.0.9.1
Ignoring ffi-1.9.17 because its extensions are not built. Try: gem pristine ffi
--version 1.9.17
Ignoring nio4r-1.2.1 because its extensions are not built. Try: gem pristine
nio4r --version 1.2.1
Ignoring nokogiri-1.7.1 because its extensions are not built. Try: gem pristine
nokogiri --version 1.7.1
Ignoring nokogiri-1.7.0.1 because its extensions are not built. Try: gem
pristine nokogiri --version 1.7.0.1
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/stub_specification.rb:151:in
`missing_extensions?': undefined method `missing_extensions?' for nil:NilClass
(NoMethodError)
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/basic_specification.rb:71:in
`contains_requirable_file?'
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1037:in
`block in find_by_path'
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1036:in
`each'
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1036:in
`find'
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1036:in
`find_by_path'
from /opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems.rb:209:in
`try_activate'
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:126:in
`rescue in require'
from
/opt/circleci/ruby/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in
`require'
	from <internal:gem_prelude>:6:in `<internal:gem_prelude>'

extconf failed, exit code 1

Gem files will remain installed in
/home/ubuntu/kundportalen/vendor/bundle/ruby/2.3.0/gems/json-2.0.3 for
inspection.
Results logged to
/home/ubuntu/kundportalen/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/json-2.0.3/gem_make.out

An error occurred while installing json (2.0.3), and Bundler cannot
continue.
Make sure that `gem install json -v '2.0.3'` succeeds before bundling.

bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 returned exit code 5

Action failed: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
```

This is currently my bundle config:

```
dependencies:
  pre:
    - gem uninstall bundler
    - gem install bundler
  override:
    - bundle install --path=vendor/bundle --jobs=4 --retry=3 
```
````

---

<div class="post-metadata">

**Author:** ![pocheptsov](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/pocheptsov/32/15171_2.png) [@pocheptsov](https://discuss.circleci.com/u/pocheptsov)\
**Post date:** [May 16, 2017, 2:57pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827/8 "2017-05-16T14:57:18Z")

</div>

The same issue and it seems that may be related to the free vs paid container as I have a feeling that it’s happening on the same one again and again. It also may be the case that it’s not enough memory on build container to perform an installation of gems with native extensions. Build without cache helps though.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [June 1, 2018, 2:21pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827/9 "2018-06-01T14:21:51Z")

</div>

I apologize we never responded to this issue. Changing the ruby version on 1.0 caused the cache to become invalid due to compiled binaries. On 1.0 this would require CircleCI staff to delete the caches.

On CircleCI 2.0 this is less of a problem because you can roll your cache keys yourself. See this doc for more details [https://circleci.com/docs/2.0/caching/#clearing-cache](https://circleci.com/docs/2.0/caching/#clearing-cache)

Closing thread as 1.0 is being EOL and this issue can be self-resolved on 2.0.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [June 1, 2018, 2:21pm UTC](https://discuss.circleci.com/t/ruby-build-error/11827/10 "2018-06-01T14:21:56Z")

</div>

Closed on June 1, 2018, 2:21pm UTC


