postgresql gem with ruby 2.0.0-p353 on mac wont suceed - ruby-on-rails

I'm trying to bundle a new rails app using Postgres.
I get this error each time I try to bundle.
Errno::EACCES: Permission denied - /usr/local/var/rbenv/versions/2.0.0- p353/lib/ruby/gems/2.0.0/gems/pg-0.17.0/.gemtest
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.0'` succeeds before bundling.
When I try to install the pg gem with sudo it says:
➜ wandrr sudo gem install pg -v '0.17.0'
Password:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.0.0-p353/bin/ruby 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.
I've read pg app's documentation and still not sure.
My zshrc file looks like this
# Customize to your needs...
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
export RBENV_ROOT=/usr/local/var/rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
I used homebrew to install rbenv and ruby-build.
I've check ruby gems is up to date aswel.
Any suggestions on how to get the pg gem to succeed?
SOLUTION FOUND
My initial problem of trying to get gem install pg to work was due to the postgres app not working right. The problem was fixed by checking the path set in my ZSHRC file.
Here's what it looks like now:
# Customize to your needs...
PATH=/Applications/Postgres93.app/Contents/MacOS/bin:$PATH
eval "$(rbenv init -)";
Note: the docs said to use
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
however the application in this instance is called Postgres93.app

Related

gem install pg -v '0.17.1' not working for some reason

I'm trying to "bundle" by rails app in AWS EC2 Linux server. I'm getting this error for "pg" gem. Could someone help? Can't find solution.
This gem 'pg' has version of 0.17.1.
Ruby version is ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.21.0/ext
/home/ec2-user/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20180105-17661-1wdsn6j.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:
--something something something
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.21.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.21.0 for inspection.
Results logged to /home/ec2-user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.21.0/gem_make.out
I had some problem same as you when i installed gem 'pg' on centos or ubuntu.
For centos, you can do this:
yum install postgresql-libs
yum install postgresql-devel
Then run gem install pg again.
On Ubuntu, I needed to run:
sudo apt-get install libpq-dev

With Ruby On Rails 4.2.5.1 I can gem install therubyracer but bundle fails on OS X 10.11.1

Using rbenv for a Ruby 2.3.0 environment on OS X 10.11.1 I am unable to get therubyracer Gem to install when using 'bundle'.
This is successful:
> gem install therubyracer
Building native extensions. This could take a while...
Successfully installed therubyracer-0.12.2
Parsing documentation for therubyracer-0.12.2
Done installing documentation for therubyracer after 0 seconds
1 gem installed
In my Gemfile:
gem 'therubyracer', '0.12.2', platforms: :ruby
This fails:
> bundle
Installing therubyracer 0.12.2 (was 0.12.1) with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/jsidlosky/code/sentons/websocket-rails-demo/.bundle/gems/therubyracer-0.12.2/ext/v8
/Users/jsidlosky/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20160215-9105-1s1s0pv.rb extconf.rb
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
checking for v8.h... no
*** 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.
....
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/jsidlosky/code/sentons/websocket-rails-demo/.bundle/extensions/x86_64-darwin-15/2.3.0-static/therubyracer-0.12.2/mkmf.log
The mkmf.log file's error is:
conftest.c:3:10: fatal error: 'v8.h' file not found
Some things I've tried:
From: How to install therubyracer gem on 10.10 Yosemite?
git clone https://github.com/cowboyd/libv8.git
cd libv8
bundle install
bundle exec rake clean build binary
gem install pkg/libv8-3.16.14.13.gem
From: Bundle install tries to use cache file
Adding to ~/.bundle/config
BUNDLE_PATH: .bundle
BUNDLE_DISABLE_SHARED_GEMS: "1"
I also tried this:
bundle config build.libv8 --with-system-v8
I've now spent well over 5 hours trying other random ideas from various StackOverflow questions and other sites. So far, nothing gets me a working therubyracer inside "bundle" even though "gem install therubyracer" works just perfectly.
I will be very grateful for any pointers or solutions.
It appears from the comment from: github.com/cowboyd/therubyracer/issues/359
"I wasn't able to get any of the above solutions to work (or rather, everything I could get to work would have required the rest of my team to rebundle). After switching from rbenv to RVM, however, bundle install ran without a hitch."
I tried switching from rbenv to RVM and it worked perfectly. I can now 'bundle' and therubyracer gem installs perfectly.

Broken Rails setup / pg gem

UGH... I broke my (formerly functioning) Rails setup - under OS X Yosemite. I did so using Homebrew to update my version of Git. After getting Git where I want it, running 'rails c' gives these errors:
/Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg.rb:4:in `require': dlopen(/Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/lib/libpq.5.6.dylib (LoadError)
Referenced from: /Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle
Reason: image not found - /Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle
Seeing the reference to pg_ext, I tried to verify pieces of my postgresql installation. If I try 'gem install pg' or try to update the gem with bundler, I get this:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/grogers/.rbenv/versions/2.0.0-p353/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
*** 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.
I'm probably making my problem worse, but I went back and redid a 'brew install postgres' but still get the same error.
Any help appreciated. Thank you!
Did you also upgrade Postgresql via Homebrew? If not, what version of Postgres are you running, and how do you install it?
If you did upgrade your Postgres you'll need to rebuild the native bindings for the pg gem: gem uninstall pg && gem install pg.

Server install stuck with error: Could not find pg-0.17.1 in any of the sources (Bundler::GemNotFound)

Trying to get Ruby 2.0.0 running on CentOS 6.5 with nginx and Passenger. So far, having no luck due to the error: http://prntscr.com/3egoca
This is the process I used for installing the PostgreSQL server for use with Ruby:
sudo vi /etc/yum.repos.d/CentOS-Base.repo
# In both [base] and [updates] sections I added the following line to the file above:
# exclude=postgresql*
sudo rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
sudo yum install postgresql93 postgresql93-devel postgresql93-server postgresql93-libs postgresql93-contrib
sudo /etc/init.d/postgresql-9.3 initdb
sudo service postgresql-9.3 start
sudo chkconfig --levels 235 postgresql-9.3 on
# At the bottom of this file I changed authentication method to md5:
sudo vi /var/lib/pgsql/9.3/data/pg_hba.conf
sudo service postgresql-9.3 restart
So far so good and PostgreSQL works as expected when tested, but then this is where it fails:
bundle install
This gives me the error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/deploy/.rvm/rubies/ruby-2.0.0-p451/bin/ruby 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.
So I followed that advice and tried installing the PG gem separately like so:
gem install pg -- --with-pg-config=/usr/pgsql-9.3/bin/pg_config
When I try that, I get this output:
Building native extensions with: '--with-pg-config=/usr/pgsql-9.3/bin/pg_config'
This could take a while...
Successfully installed pg-0.17.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.17.1
unable to convert "\xF0" from ASCII-8BIT to UTF-8 for ../../extensions/x86_64-linux/2.0.0/pg-0.17.1/pg_ext.so, skipping
unable to convert "\xF0" from ASCII-8BIT to UTF-8 for lib/pg_ext.so, skipping
1 gem installed
Despite saying it successfully installed I still get the Passenger error I posted a screenshot of and I still can't get bundle install to run successfully.
BTW, I am SSH'd in as user 'deploy' which is what nginx is also set as the user in the nginx.conf file.
Try:
export PATH=/usr/pgsql-9.3/bin:$PATH
bundle install

Cannot install the gem pg -v '0.15.1'

I have tried installing the packet libpq-dev, and installing postgresql, but bundle install still fails due to gem pg. This is the error I get:
$ gem install pg -v '0.15.1'
Building native extensions. This could take a while...
/.rvm/rubies/ruby-1.9.3-
p484/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:73: warning: Insecure
world writable dir /usr/local in PATH, mode 040777
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/.rvm/rubies/ruby-1.9.3-p484/bin/ruby 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.
What is a proper way to clean up the mess?
If you are on Mac, install Homebrew and then install Postgres using the command
brew install postgresql
Or you can download and install Postgres from here depending on which OS you are using.
There isn't any "mess" - it's a standard issue where your system does not have the required libraries to install the gem
Library
As mentioned in the comments, you first need to install PGSQL, which will create the required library files to help the gem install, after that you can use some path references to help the gem install:
gem install pg -- --with-pg-dir="C:/Program Files/installer

Resources