Kush Trivedi
Kush Trivedi

Reputation: 370

Migrating from ruby to jruby

I am migrating from ruby-2.5.7 to jruby-9.2.12.0, when I run bundle install after the changing ruby-version & gemfile I get an error in pg-gem.

Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/kush/.rvm/gems/jruby-9.2.12.0/gems/pg-1.2.3/ext
/Users/kush/.rvm/rubies/jruby-9.2.12.0/bin/jruby -I
/Users/kush/.rvm/rubies/jruby-9.2.12.0/lib/ruby/stdlib -r
./siteconf20200707-6808-16ipijl.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.

try_do at
/Users/kush/.rvm/rubies/jruby-9.2.12.0/lib/ruby/stdlib/mkmf.rb:456
try_link0 at
/Users/kush/.rvm/rubies/jruby-9.2.12.0/lib/ruby/stdlib/mkmf.rb:541
try_link at
/Users/kush/.rvm/rubies/jruby-9.2.12.0/lib/ruby/stdlib/mkmf.rb:556
     <main> at extconf.rb:40
*** extconf.rb failed ***

I have already installed developer-tools & also have Xcode in my mac.

Any help is highly appreciated!

Upvotes: 1

Views: 418

Answers (1)

Holger Just
Holger Just

Reputation: 55748

The pg gem is highly specific to MRI (that is the "standard" ruby) and is not compatible with JRuby. As such, you should use a different database adapter here.

The most commonly used adapters in JRuby are JDBC based. There are wrappers available for JRuby for most database database types. To use the PostgreSQL adapter used with Rails, you can use it with the activerecord-jdbcpostgresql-adapter gem. For that, replace the

gem "pg"

line on your Gemfile with

gem "activerecord-jdbcpostgresql-adapter"

See https://github.com/jruby/activerecord-jdbc-adapter/blob/master/README.md for configuration and usage details.

Upvotes: 2

Related Questions