asdf: plugin version not resolved with ruby pg gem
Steps to reproduce
- set up
.tool-versionswith:
postgres 9.4.7
ruby 2.6.2
-
asdf install(successful) -
gem install bundler(successful) -
gem install pg
Expected behavior
The pg gem should be able to build its native extensions as part of installation.
Its build process relies on pg_config, which is shimmed via the postgres plugin.
Actual behavior
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/mike/.asdf/installs/ruby/2.6.2/lib/ruby/gems/2.6.0/gems/pg-1.1.4/ext
/Users/mike/.asdf/installs/ruby/2.6.2/bin/ruby -I /Users/mike/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0 -r ./siteconf20190329-82337-1d85knm.rb extconf.rb
checking for pg_config... yes
Using config values from /Users/mike/.asdf/shims/pg_config
asdf: No version set for command pg_config
you might want to add one of the following in your .tool-versions file:
postgres 9.4.7
asdf: No version set for command pg_config
you might want to add one of the following in your .tool-versions file:
Environment
OS: macOS 10.14.3
asdf version: master @ 5d40982
Comments
When executing pg_config directly from the command line, through the asdf shim, it resolves to the correct pg_config binary and runs successfully. The problem occurs when the pg_config shim is invoked in the context of gem install.
After adding some debug output to lib/utils.sh, I can see that search_path is populated from pwd, which in this case is: /Users/mike/.asdf/installs/ruby/2.6.2/lib/ruby/gems/2.6.0/gems/pg-1.1.4/ext. As a result, usable_plugin_versions remains empty.
It seems that asdf assumes that pwd is going to return the directory in which my .tool-versions lives, which does have postgres 9.4.7 in it.
For now, the way I’m working around this is to set a bundler config to circumvent the use of the pg_config shim and use the installed pg_config binary directly.
Possibly related: #488
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 8
- Comments: 19 (7 by maintainers)
@ashmckenzie the
asdf wherecommand can be helpful in commands like those:gem
bundle
environment variable
As long as you run these commands in a directory where you have the correct postgres version set everything will work.
setting
asdf global postgres 9.4.7helped meIn the context of postgres installed via
asdfbut no global version set,gemandbundleneed a helping hand. It’s important to use the full postgres install path, not the ‘shim’ path because that won’t work:gem
bundle
or if you don’t want to use an environment variable:
This is still an issue. Setting it to
globalthough works but I think not really the solution we’re looking for. For now manually installing thegem pgusing the--with-pg-configwill do.Same as @mpugach - doing
asdf global postgres 11.5sorted it for meOnly adding the
pg_configflag didn’t work for me. I had to do this instead:I also needed to do
brew install postgres. I guesspgneeds postgres on the system already, either from asdf or just brew or any other way.That sounds great @jthegedus !
We could have a “kitchen sink” page in the docs under a recipes section that captures these edge cases where we document and update the caveats. It might help direct people searching the web to a solution than to opening new Issues or piling on old threads. Thoughts?
Also worked for me
gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"I don’t have any ideas. I don’t think passing
pwdto any shim is viable because other (non-asdf) commands would have to pass it along. If I understand this problem correctly Ruby’sgemcommand would have to actually passpwdto thepg_configshim:gem installgem installdoes some magic to install the gem, eventually tries to invokepg_configin another directory that doesn’t have a .tool-versions` file and the command fails with the version error message.