简体   繁体   中英

Rails - Gem Error while installing pg (1.1.3), and Bundler cannot continue

I am still fairly new to Rails. I am trying to push to Heroku and I am getting errors.

The first error is when I run a Bundle Install I get this error message:

"An error occurred while installing pg (1.1.3), and Bundler cannot continue. Make sure that gem install pg -v '1.1.3' succeeds before bundling."

I have tried to run this command

gem install pg -v '1.1.3'

But it fails and gives me this error message:

"ERROR: Error installing pg: ERROR: Failed to build gem native extension."

Does anyone have a solution to this?

I had the exact same problem, and solved it by running sudo apt install postgresql-contrib libpq-dev . Then bundle worked just fine.

if you're using OSX, you could try running

brew install postgresql

and then installing the gem

I encountered the same problem. I am using Ubuntu. I installed Postgres using this Ubuntu guide . After installing Postgres, I ran this code sudo apt install postgresql-contrib libpq-dev then bundle install.

try instaling with pg-config like this:
gem install pg -v 1.1.3 -- --with-pg-config=/usr/pgsql-9.X/bin/pg_config .

In pg-config path mention the posgtres version installed in you're system.

The following is only for your local environment:

Note: Update the command below to match your version postgresql/13.2/...

> brew install postgres
> sudo gem install pg -v '1.1.4' --source 'https://rubygems.org/' -- --with-pg-config=/usr/local/Cellar/postgresql/13.2/bin/pg_config

Also, make sure to start your server > pg_ctl -D /usr/local/var/postgres start

TL;DR; If you installed the Postgres using the PostgresAPP instead of BREW then the problem might be that you don't have the postgres bin folder in the $APTH

The solution is to find the Posgres app installation folder an in it the /bin folder.

In my case if I run which postgres doesn't work which means I don't have it in my $PATH, so what I did is I navigated to: cd /Applications/Posgres.app then to Contents and then to Versions until I found the latest folder:

/Applications/Postgres.app/Contents/Versions/latest/bin

Now, with this I can install the PG GEM by providing the path to the bin folder of my Postgres app installation

Finally, in the terminal in the root of my Rails project I ran where I provide the postgres config file path to the GEM installer:

gem install pg -v '1.2.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

Postgresql needs to be in local in order to install gem pg. Try this

brew install postgresql

and the re-install bundle

bundle install

or If you are using yum. Try this

sudo yum install postgresql-devel

The accepted answer is not correct. If you installed postgresql-contrib and libpq-dev as mentioned in Cesar Faria answer, and you still getting the same error, most probable you missed the list of packages which are considered essential for building Debian packages. All that packages included in build-essential package. So, all you need to do to get rid of the error is the command below.

sudo apt install libpq-dev build-essential

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM