Error installing pg gem after running bundle - ruby-on-rails

I'm on Mac OS X El Capitan (10.11.6):
When trying to run bundle, I get an error after it tries to install pg.
Trying to run gem install pg also fails.

Solution:
Note: Before doing the below steps, make sure you have Xcode installed, and homebrew.
brew install postgresql
gem uninstall pg - this might not return anything, that's ok.
either bundle install in your application's root or gem install pg

Related

error occurred while installing pg (0.17.1)

When I run a bundle on a rails project I seem to be getting the following:
Installing pg 0.17.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r
./siteconf20151024-43303-t81fnp.rb extconf.rb checking for
pg_config... yes Using config values from /usr/local/bin/pg_config An
error occurred while installing pg (0.17.1), and Bundler cannot
continue. Make sure that gem install pg -v '0.17.1' succeeds before
bundling.
I have visited the following SO questions:
An error occurred while installing pg (0.17.1), and Bundler cannot continue
Installing pg -v 0.17.1
Installing PG gem on OS X - failure to build native extension.
Additionally to this I've tried executing the following:
gem install pg
env ARCHFLAGS="-arch x86_64" gem install pg
gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.4.5/bin/pg_config
And I keep getting:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
FYI I have rbenv installed too. Also tried a rbenv rehash also and executed the above commands and have had no luck. I've also tried uninstalling and reinstalling Postgres and get the same. To also be on the safe side i've also ran:
brew update
brew uinstall posgresql > brew install postgresql
updated Xcode
Info:
Mac OSx Yosemite 10.10.5
Postgres v9.4.5
rbenv v0.4.0
rbenv global => 2.0.0-p247
I don't know Mac, but I've had this problem on Windows.
--
The issue is here:
Failed to build gem native extension
When you install a gem, many of the advanced ones actually compile / "build" through the extconf.rb file. I've forgotten the significance of this, but it basically allows the gem to run natively on the OS environment you're using.
In short, the error occurs because your OS does not have access to the "developer headers" the gem requires to compile.
The most common instance of this problem is with the mysql2 gem on Windows, but happens for others too.
--
What you need is to download PGSQL on your system before attempting to install the gem.
After installing PGSQL, you may need to reference the developer headers with some "switches", but it does not appear to be the case in this instance:
Installing PG gem on OS X - failure to build native extension
Install Xcode command line tools (Apple Developer site)
brew uninstall postgresql
brew install postgresql
ARCHFLAGS="-arch x86_64" gem install pg
Maybe this won't work? I don't know... I know that in Windows, you have to install the binaries before expecting the gem to work.
Greetings I hope I can help. May I ask how you created your rails project? Did you simply use:
rails new *appname*
If so maybe try creating a new rails app like so:
rails new *appname* -d postgresql
And before you create your database and run migrations/seed, you should go into "config/database.yml" and change the username and password to the postgreSQL user that you've hopefully setup after installing postgreSQL on your machine.
Good Luck!

Nokogiri won't let me bundle install in Rails

I've seen this question asked and tried everything I've seen suggested.
I got a new macbook and am looking to set up an existing app. When i clone the app, it will not bundle install and acts like Rails is not installed, even though it works in other directories.
I tried removing version numbers from gemfile and deleting gemfile.lock. I tried bundle update. I'm on osx 10.9.4, rails 4.1.5 and ruby 2.1.1.
the error I am getting:
An error occurred while installing nokogiri (1.6.3.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.3.1'` succeeds before bundling.
I have rvm installed. I tried reinstalling homebrew, rails and ruby.
What could it be?
Ok, phew. This worked:
http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/
xcode-select --install
gem install nokogiri
bundle config build.nokogiri --use-system-libraries
bundle install
then, the pg gem wouldnt let bundle install. this fixed it - Installing PG gem on OS X - failure to build native extension
brew update
brew install postgresql
gem install pg
then... bundle install worked, finally, but rails s was giving me an error, which this fixed: Devise Secret Key was not set
just had to add the line w/the secret key to the config/initializers/devise.rb right before the last 'end'
hope this helps anyone who upgrades to Mavericks / gets a new computer that comes with it installed!
First try to do this sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev, then try to install

An error occurred while installing pg (0.17.1), and Bundler cannot continue

I just installed Rails 4.0.2 and when creating a new app, in the bundle stage I get:
Installing pg (0.17.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/Dee/.rvm/rubies/ruby-2.0.0-p247/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.
How do I fix this?
Some kind of error resported here Installing PG gem on OS X - failure to build native extension
To install dependencies on Ubuntu try this:
sudo apt-get install libpq-dev
and this
gem install pg
I'm on a Mac running Mavericks. My solution was to install Postgres.
And then in terminal install using homebrew with the configuration:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
Note: This answer has been edited to use the latest symlink that is currently included in shipping versions of the Postgres app.
Previous versions suggested:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
app root:
brew update
brew install postgres
gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
bundle install
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
createuser -s -r postgres
rake db:create:all
rake db:migrate
rails s
NOTE: replace the version number in step 3 if needed.
Previously working answer with older version
I installed under mac OSX Mavericks, having the postgres app (Version 9.2.2.0 ) from www.postgresapp.com installed. The underlying problem was simpy that the since postgres was installed via the app, the configuration file resides on a location which is not the default one when installing it without postgressapp. so we need to tell gem where to find this file by:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Hope it helps
If gem install pg fails, try the following command:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
... from the PostgreSQL.app Documentation
Looks like you do not have PostgreSQL installed. The pg gem requires some headers from PostgreSQL to compile native extension.
I had to combine everything and use
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
If you are using something other than Postgres in development and Postgres in production only, you can add the pg gem to your gemfile like so...
group :production do
gem 'pg', '0.17.1'
end
Then use bundle install --without production
For CentOS users:
sudo yum install postgresql-devel
and
gem install pg
I have just set up a new Macbook Pro which was prebuilt with Catalina.
What worked for me:
Install the Postgres from here: https://postgresapp.com/
Add export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"to your .zshenv, since Z shell is now the default terminal.
On mac this command worked for me.
gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"
After installing Postgres I had to run the following command
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
After this bundle install works great!
Hope it helps
The way I managed to get past that error was:
cd to app folder and then set the ruby version locally. I'm using ruby 2.1.2.
rbenv local 2.1.2
instead of just running bundle install, install the gems in vendor/bundle
bundle install --path vendor/bundle
This did it for me.
I needed to use sudo
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
I was having a problem with Amazon and couldn't use apt-get.
For my worked:
sudo yum install postgresql-devel
then:
bundle install
and try again:
rails serve
If you installed through Homebrew; gem install pg -- --with-pg-config=/usr/local/bin/pg_config. Works with Ruby 2.4.6 and pg 0.20.0.
It works for me
rvm list gemsets
rvm use ruby-2.4.1
bundle
]2

Rails: Installing PG gem on OS X - failure to build native extension

It seems many others have had problems installing the pg gem. None of the solutions posed for others have worked for me.
I have tried to install the pg gem and postgres.app. The pg gem won't install. The first error I get is:
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.
The installation advice about pointing my gem install to the config for pg fails with the following error message (which many others on this forum have encountered):
Failed to build native extensions... Results logged to /Users/melanie/.rvm/gems/ruby-1.9.3-p448/gems/pg-0.17.0/ext/gem_make.out
I don't know how to find or access this log file to search for further clues.
I also get an error message (command not found) when I try using the sudo apt-get install command. I've scoured this forum for the last 6 hours, trying each piece of advice to get pg working with my rails project.
I can't find advice about how to change a path, or specifically, what change is required. My which pg_config returns a file source. I've used that with a command to install pg using that config. It fails.
There are so many people that have had trouble with this. Many answers suggest homebrew. I've had to remove that because it threw up other issues.
Same error for me and I didn't experience it until I downloaded OS X 10.9 (Mavericks). Sigh, another OS upgrade headache.
Here's how I fixed it (with homebrew):
Install another build of Xcode Tools (typing brew update in the terminal will prompt you to update the Xcode build tools)
brew update
brew install postgresql
After that gem install pg worked for me.
If you are using Ubuntu try to install following lib file
sudo apt-get install libpq-dev
and then
gem install pg
worked for me.
I am using OS X Mavericks (version 10.9)
and when I run the above I got the following message: If builds of PostgreSQL 9 are failing and you have version 8.x installed.
So I run the following command:
ARCHFLAGS="-arch x86_64" gem install pg
and this worked for me, I hope this helps someone :)
Ok I also had this problem (psql is v 9.3.0 and ruby is v 2.1.2) and the solution that worked for me was setting the bundle config settings first:
bundle config build.pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
This answer finally helped me figure it out: https://stackoverflow.com/a/9235107/3546680
I tried everything for hours but the following finally fixed it (I'm on OS X 10.9.4):
Install Xcode command line tools (Apple Developer site)
brew uninstall postgresql
brew install postgresql
ARCHFLAGS="-arch x86_64" gem install pg
easy step
brew install postgresql
gem install pg -v 'your version'
Similarly, after installing Mavericks bundle update was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just brew uninstall postgresql, then brew install postgresql. After which I was immediately able to successfully run bundle update.
I believe the “correct” answer would be to first configure PATH correctly for Postgres.app by adding the following to ~/.profile (.zshrc or ~/.zprofile if using ZSH):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
Then open a new tab or window in terminal and install the pg gem with:
ARCHFLAGS="-arch x86_64" gem install pg
Documented here:
https://postgresapp.com/documentation/cli-tools.html
https://postgresapp.com/documentation/configuration-ruby.html
On OSX with Postgres installed in /Applications, I simply run the following command (change 0.20 & 9.4 according to your version)
gem install pg -v '0.20' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
You should have :
Building native extensions with:
'--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config'
This could take a while... Successfully installed pg-0.20.
running brew update and then brew install postgresql worked for me, I was able to run the pg gem file no problem after that.
I spent a day on this and here's how I got it fixed:
I found that global value of build.pg was set to: /opt/local/lib/postgresql91/bin/pg_config
and that was not where postgres was installed.
I fixed it with replacing the value of build.pg to:
bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.4.4/bin/pg_config
which is where my postgresql installation is.
Try:
gem install pg -- --with-pg-config=`which pg_config`
Solved!
I found some lack of library for PostgreSQL on the system.
Only two steps solved it:
brew install postgresql
Then run
gem install pg
For those who are not interested to use brew.
Download PostgreSQL application.
Follow the macOS default instruction to install it.
It is advisable to run PostgreSQl.
Run gem install pg -- --with-pg-config=/path/to/postgress/in/your/applications/folder/`
For example, in my machine it is
/Applications/Postgres.app/Contents/Versions/12/bin/pg_config
i got same problem and i solved
gem update --system 3.0.6

Ruby on Rail error installing SQLite, permissions problems

I've installed Ruby 1.8.7 and Rails 3.1.1 on my Mac OS X Leopard. However I wasn't able to install the SQLite gem. I've seen plenty solutions here, but none of the workout for me. Every time I tried to bundle my app I get this error when it comes to the SQLite gem:
Errno::EACCES: Permission denied -/Users/eduardoribeiro/sites/models/vendor/bundle/ruby/1.8/gems/sqlite3-1.3.4/API_CHANGES.rdoc
An error occured while installing sqlite3 (1.3.4), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.4'` succeeds before bundling.
I'm running
$ sudo bundle install
It seems that the compiler it's trying to install the sqlite dependecies inside of the folder of my app. I had the PATH correctly defined and even created a .bash_profile in the root of Mac OS X.
Any ideas?
Have you tried running gem install sqlite3 -v '1.3.4' at all before running bundle install ?
That could be your problem, if not try sudo gem install sqlite3 -v '1.3.4' then bundle install again.

Resources