gem install pg for ruby on rails - ruby-on-rails

Postgresql will not install on OSX
here is my data below
n error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that gem install pg -v '0.18.4' succeeds before bundling.
chriss-MacBook-Pro:shine chriswilson$ bundle exec install
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
[-o owner] file1 file2
install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
[-o owner] file1 ... fileN directory
install -d [-v] [-g group] [-m mode] [-o owner] directory ...
chriss-MacBook-Pro:shine chriswilson$ gem install pg -v '0.18.4'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/ext
/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160902-1617-e1qwb1.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/gem_make.out
chriss-MacBook-Pro:shine chriswilson$ gem install pg -v '0.18.4'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/ext
/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160902-1643-jfhxyo.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/gem_make.out
find_executable: checking for pg_config... -------------------- no
--------------------
find_header: checking for libpq-fe.h... -------------------- no
"gcc -o conftest -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/x86_64-darwin15 -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/backward -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0 -I. -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/chriswilson/.rvm/rubies/ruby-2.3.0/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -lruby.2.3.0 -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
"gcc -E -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/x86_64-darwin15 -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/backward -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0 -I. -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
/* end */
--------------------

This basically means that you're missing a library or program on your setup. I've had this issue a couple of times now so here are a few different things to try (hopefully one of them will work for you):
Install a common missing library:
brew install libpqxx
gem install pg
Reinstall postgres (not ideal I know):
brew uninstall postgresql
brew install postgresql
gem install pg
Explicitly define path of pg_config:
1) Get location of pg_config
which pg_config
2) pass that path into gem install
gem install pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config

Try this it will work
sudo apt-get install -y libpq-dev build-essential postgresql-server-dev-all libpgsql-ruby postgresql ruby-dev && gem install pg

Related

Rails new app_name fails due to Sqlite3 problem

On Windows 10 64bit
Using Railsinstaller I installed the bundler necessary to build my App.
After the installation I checked the versions of:
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
$ rails -v
Rails 5.2.2
$ gem -v
2.5.2
$ bundler -v
Bundler version 2.0.1
$ sqlite3 --version
3.8.7.2 2014-11-18 20:57:56 2ab564bf9655b7c7b97ab85cafc8a48329b27f93
Then I started rails new my_app_name which ended with these errors:
mkmf.log
package configuration for sqlite3 is not found
find_header: checking for sqlite3.h... -------------------- no
"gcc -o conftest.exe -IC:/RailsInstaller/Ruby2.3.3/include/ruby-2.3.0/i386-mingw32 -IC:/RailsInstaller/Ruby2.3.3/include/ruby-2.3.0/ruby/backward -IC:/RailsInstaller/Ruby2.3.3/include/ruby-2.3.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/RailsInstaller/Ruby2.3.3/lib -L. -lmsvcrt-ruby230 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7: return 0;
8: }
/* end */
"gcc -E -IC:/RailsInstaller/Ruby2.3.3/include/ruby-2.3.0/i386-mingw32 -IC:/RailsInstaller/Ruby2.3.3/include/ruby-2.3.0/ruby/backward -IC:/RailsInstaller/Ruby2.3.3/include/ruby-2.3.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -o conftest.i"
conftest.c:5:21: fatal error: sqlite3.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: #include <sqlite3.h>
/* end */
--------------------
And gem_make.out
current directory: C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0/ext/sqlite3
C:/RailsInstaller/Ruby2.3.3/bin/ruby.exe -r ./siteconf20190214-3564-1lpwzs0.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/RailsInstaller/Ruby2.3.3/bin/$(RUBY_BASE_NAME)
--with-sqlcipher
--without-sqlcipher
--with-sqlite3-config
--without-sqlite3-config
--with-pkg-config
--without-pkg-config
--with-sqlcipher
--without-sqlcipher
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sqlite3-1.4.0/mkmf.log
extconf failed, exit code 1
I am total beginner with Ruby and this is my first attempt to create app so I can experiment. It seems to me that the problem is related with the Sqlite3 version. I tried to update it via gem and bundle but I got error again.
I have got the same issue and these are the two solutions I found.
1* After the bundle install fail to enter on the project folder and modify the Gemfile
gem 'sqlite3', '1.3.11'
this line change it by some of these 3 below
gem 'sqlite3', git: "https://github.com/sparklemotion/sqlite3-ruby"
gem 'sqlite3', git: "https://github.com/sparklemotion/sqlite3-ruby", branch: "add-gemspec"
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
It only works if you've installed first Ruby Devkit or RubyInstaller and later Rails Installer, otherwise Rails Installer Ruby folder will be choosed by system as "ruby folder"
2* you'll have to uninstall RailsInstaller and remove the remaining folder(if you don't remove manually the folder after uninstaller ends, when you execute gem command it'll says "RailsInstaller/Ruby2.3.3/bin" folder not found)
Ok, after it install rails by command line
gem install rails
And install by command line MinGW
C:\Sites>ridk exec pacman -S mingw-w64-x86_64-dlfcn
Download the gem file from https://rubygems.org/ and save it locally and install from file
gem install --local C:\sqlite3-1.4.0.gem
This second solution works globally so you've to run it only once and the next time you execute rails new blog the issue with sqlite won't appear again. Just make sure to execute it on the Sites folder not inside any project or it'll work only for that project.
If any of these works for you please feel free to try one of the methods I mention here https://mycodeissuesandfixes.blogspot.com/2019/02/ruby-on-rails-issue-about-sqlite-3-gem.html , I've tried to find a solution for more than a week to this.
Good Luck!! Hope it helps you

Installing Postgres gem on Rails 5.2 throws error – Gem::Ext::BuildError: ERROR: Failed to build gem native extension

I'm trying to set up a Rails project with Vagrant. Using Rails 5.2 as well.
In my original bundle install, it told me
Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.
...So I tried that and got:
Fetching pg 1.0.0
Installing pg 1.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /app/vendor/bundle/ruby/2.5.0/gems/pg-1.0.0/ext
/usr/local/bin/ruby -r ./siteconf20180501-2212-1algyv4.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/app/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.0.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /app/vendor/bundle/ruby/2.5.0/gems/pg-1.0.0 for inspection.
Results logged to /app/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.0.0/gem_make.out
An error occurred while installing pg (1.0.0), and Bundler cannot continue.
Make sure that `gem install pg -v '1.0.0'` succeeds before bundling.
Looking at the log file mentioned has this in it:
find_executable: checking for pg_config... -------------------- no
--------------------
find_header: checking for libpq-fe.h... -------------------- no
"gcc -o conftest -I/usr/local/include/ruby-2.5.0/x86_64-linux -I/usr/local/include/ruby-2.5.0/ruby/backward -I/usr/local/include/ruby-2.5.0 -I. -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn conftest.c -L. -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
"gcc -E -I/usr/local/include/ruby-2.5.0/x86_64-linux -I/usr/local/include/ruby-2.5.0/ruby/backward -I/usr/local/include/ruby-2.5.0 -I. -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn conftest.c -o conftest.i"
conftest.c:3:22: fatal error: libpq-fe.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
/* end */
Unclear how to proceed and get this working. Would love some help or advice. Thanks!
Edit:
I run sudo apt-get install libpq-dev and then get an error related to and old version.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /tmp/bundler20180501-4263-lecb9zpg-1.0.0/gems/pg-1.0.0/ext
/usr/local/bin/ruby -r ./siteconf20180501-4263-1qowxi6.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQsetSingleRowMode()... no
Your PostgreSQL is too old. Either install an older version of this gem or upgrade your database to at least PostgreSQL-9.2.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Installing Wit gem causes obscure Ruby error

I created a brand new Rails app and added gem wit to the Gemfile. Now, when I run bundle install, I get this error. In Googling to find a solution, I came across four different possibilities but none of them apply to my dev environment (OSX 10.9.5, Brew 0.9.5). Has anyone solved this issue?
Links:
The compiler failed to generate an executable file. (RuntimeError)
https://github.com/CocoaPods/CocoaPods/issues/1727
https://github.com/copiousfreetime/hitimes/issues/26
https://teamtreehouse.com/forum/rails-gem-wont-install-properly
...
Using turbolinks 2.5.2
Using uglifier 2.5.3
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-2.1-head/bin/ruby -r ./siteconf20141204-96223-d2ceuv.rb extconf.rb
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.7M 100 12.7M 0 0 741k 0 0:00:17 0:00:17 --:--:-- 723k
checking for main() in -lsox... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/user/.rvm/rubies/ruby-2.1-head/bin/ruby
--with-wit-dir
--without-wit-dir
--with-wit-include
--without-wit-include=${wit-dir}/include
--with-wit-lib
--without-wit-lib=${wit-dir}/lib
--with-soxlib
--without-soxlib
/Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:541:in `try_link0'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:556:in `try_link'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:742:in `try_func'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:973:in `block in have_library'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
from /Users/user/.rvm/rubies/ruby-2.1-head/lib/ruby/2.1.0/mkmf.rb:968:in `have_library'
from extconf.rb:33:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Users/user/.rvm/gems/ruby-2.1-head/gems/wit-1.0.5 for inspection.
Results logged to /Users/user/.rvm/gems/ruby-2.1-head/extensions/x86_64-darwin-13/2.1.0/wit-1.0.5/gem_make.out
An error occurred while installing wit (1.0.5), and Bundler cannot continue.
Make sure that `gem install wit -v '1.0.5'` succeeds before bundling.
Here is the output for mkmf.log
$ cat /Users/user/.rvm/gems/ruby-2.1-head/extensions/x86_64-darwin-13/2.1.0/wit-1.0.5/mkmf.log
"/usr/bin/clang -o conftest -I/Users/user/.rvm/rubies/ruby-2.1-head/include/ruby-2.1.0/x86_64-darwin13.0 -I/Users/user/.rvm/rubies/ruby-2.1-head/include/ruby-2.1.0/ruby/backward -I/Users/user/.rvm/rubies/ruby-2.1-head/include/ruby-2.1.0 -I. -I/Users/user/.rvm/gems/ruby-2.1-head/gems/wit-1.0.5/ext/wit/libwit/include -I/Users/user/.rvm/rubies/ruby-2.1-head/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/user/.rvm/rubies/ruby-2.1-head/lib -L/Users/user/.rvm/gems/ruby-2.1-head/gems/wit-1.0.5/ext/wit/libwit/lib -L/Users/user/.rvm/rubies/ruby-2.1-head/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -lwit -lsox -lcurl -lruby.2.1.0 -lpthread -lgmp -ldl -lobjc "
ld: library not found for -lsox
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
I got this problem solved by reinstalling X-Code's Command Line tools: xcode-install --select

Install pg gem on CentOS 6

I'm trying to setup my VPS (CentOS 6.4) with ruby on rails and postgres.
I installed ruby (2.1.0p0), rails (4.1.0), and postgresql (9.3.4) with no problem.
When I try create new rails app (rails new new_app -d postgresql) it stops when installing the pg gem. I've looked into all SO posts about this error and tried pretty much everything I could find. The most suggested was to run "yum install postgresql-devel" and still didn't work.
Below you can find the ssh output and the mkmf.log. Let me know if need more information...
Output
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby
--with-pg
--without-pg
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
/home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1120:in `block in find_header'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1119:in `find_header'
from extconf.rb:48:in `'
extconf failed, exit code 1
mkmf.log
"gcc -o conftest -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/x86_64-linux -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/ruby/backward -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0 -I. -I/usr/include -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -fPIC conftest.c -L. -L/home/deploy/.rvm/rubies/ruby-2.1.0/lib -Wl,-R/home/deploy/.rvm/rubies/ruby-2.1.0/lib -L/usr/lib64 -Wl,-R/usr/lib64 -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-rpath,'/../lib' -Wl,-R -Wl,'/../lib' -L'/../lib' -lruby -lpthread -lrt -ldl -lcrypt -lm -lc"
gcc: error trying to exec 'as': execvp: Permission denied
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
Before:
For Centos 6: Right install Postgres 9.* with this guide.
After:
yum install postgresql-libs postgresql-devel
Helpful instruction:
How to setup RoR with Postgres
As you are not using the outdated PostgreSQL version that comes with CentOS 6 (PostgreSQL 8.4), you need to install the -devel package matching your version (PostgreSQL 9.X).
The easiest way is to use the official PostgreSQL yum repository.
As the latest version is 9.5 and it is compatible with all 9.X versions I will write the instructions for that one. In the future you can refer to the official instructions for the updated commands.
yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm
yum install postgresql95-devel
Then install the gem with the -with-pg-config option:
gem install pg -- --with-pg-config=/usr/pgsql-9.5/bin/pg_config
This was easier for me:
ln -s /usr/pgsql-9.5/bin/pg_config /usr/local/bin/
Try something like this;
before "bundle:install" do
run "ls -l #{fetch(:latest_release)}/Gemfile"
#run "bundle config --local --gemfile=#{fetch(:latest_release)}/Gemfile build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config"
run "cd #{fetch(:latest_release)} && bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config"
end
You could try installing the pg gem with the postres pg_config file path option:
gem install pg -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config
Please update the path according to your system
Regards
I had this problem on my mac and it was a bash / RVM issue. I had to add this to my bash:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm” . Given that it's finding the config file I would look into this.

Mac 10.8 + RVM: Installing Rails 4 Needs development tools?

I'm having issues installing Rails 4 with rvm. I saw another solution with removing rvm from my system, but that is not an option because I need isolated gemsets. This is my terminal:
Edmunds-MacBook-Pro:pipetask edmundmai$ rvm current
ruby-2.0.0-p247#pipetask
Edmunds-MacBook-Pro:pipetask edmundmai$ ls
Gemfile README.rdoc app config db lib public
Gemfile.lock Rakefile bin config.ru gcc-4.2 log vendor
Edmunds-MacBook-Pro:pipetask edmundmai$ gem install rails -v=4.0.0
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/Users/edmundmai/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/edmundmai/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-atomic_reference-dir
--without-atomic_reference-dir
--with-atomic_reference-include
--without-atomic_reference-include=${atomic_reference-dir}/include
--with-atomic_reference-lib
--without-atomic_reference-lib=${atomic_reference-dir}/
/Users/edmundmai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/edmundmai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:519:in `try_link0'
from /Users/edmundmai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:817:in `try_run'
from extconf.rb:26:in `<main>'
Gem files will remain installed in /Users/edmundmai/.rvm/gems/ruby-2.0.0-p247#pipetask/gems/atomic-1.1.14 for inspection.
Results logged to /Users/edmundmai/.rvm/gems/ruby-2.0.0-p247#pipetask/gems/atomic-1.1.14/ext/gem_make.out
Edmunds-MacBook-Pro:pipetask edmundmai$
How would I debug this? I don't even know which mkmf.log it is talking about, I have like 50 of them when I do locate mkmf.log. What is development tools? I have xcode 5 and command line tools.
==Update
This might be the mkmf.log file it was referring to?
Edmunds-MacBook-Pro:bin edmundmai$ more /Users/emai/mkmf.log
have_func: checking for rb_hash_foreach()... -------------------- yes
"clang -o conftest -I/Users/emai/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0/x86_64-darwin11.4.2 -I/Users/emai/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0/ruby/backward -I/Users/emai/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/Users/emai/.rvm/usr/include -I/Users/emai/.rvm/usr/include -O3 -g3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -pipe conftest.c -L. -L/Users/emai/.rvm/rubies/ruby-2.0.0-p0/lib -L/Users/emai/.rvm/usr/lib -L. -fstack-protector -L/Users/emai/.rvm/usr/lib -L/Users/emai/.rvm/usr/lib -lruby-static -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(void) {return 0;}
/* end */
"clang -o conftest -I/Users/emai/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0/x86_64-darwin11.4.2 -I/Users/emai/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0/ruby/backward -I/Users/emai/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/Users/emai/.rvm/usr/include -I/Users/emai/.rvm/usr/include -O3 -g3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -pipe conftest.c -L. -L/Users/emai/.rvm/rubies/ruby-2.0.0-p0/lib -L/Users/emai/.rvm/usr/lib -L. -fstack-protector -L/Users/emai/.rvm/usr/lib -L/Users/emai/.rvm/usr/lib -lruby-static -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /*top*/
4: int main(void) {return 0;}
5: extern int t(void);
6: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_hash_foreach; return 0; }
/* end */
--------------------

Resources