简体   繁体   English

Rails - 安装 pg (1.1.3) 时出现 Gem 错误,并且 Bundler 无法继续

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

I am still fairly new to Rails.我对 Rails 还是很陌生。 I am trying to push to Heroku and I am getting errors.我正在尝试推送到 Heroku,但我遇到了错误。

The first error is when I run a Bundle Install I get this error message:第一个错误是当我运行 Bundle Install 时,我收到以下错误消息:

"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." “安装 pg (1.1.3) 时出错,Bundler 无法继续。在捆绑之前确保gem install pg -v '1.1.3'成功。”

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." “错误:安装 pg 时出错:错误:无法构建 gem 原生扩展。”

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 .我遇到了完全相同的问题,并通过运行sudo apt install postgresql-contrib libpq-dev解决了它。 Then bundle worked just fine.然后捆绑工作得很好。

if you're using OSX, you could try running如果您使用的是 OSX,则可以尝试运行

brew install postgresql

and then installing the gem然后安装 gem

I encountered the same problem.我遇到了同样的问题。 I am using Ubuntu.我正在使用 Ubuntu。 I installed Postgres using this Ubuntu guide .我使用这个Ubuntu 指南安装了 Postgres。 After installing Postgres, I ran this code sudo apt install postgresql-contrib libpq-dev then bundle install.安装 Postgres 后,我运行此代码sudo apt install postgresql-contrib libpq-dev然后 bundle install。

try instaling with pg-config like this:尝试使用 pg-config 安装,如下所示:
gem install pg -v 1.1.3 -- --with-pg-config=/usr/pgsql-9.X/bin/pg_config . 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.在 pg-config 路径中​​提及您系统中安装的 posgtres 版本。

The following is only for your local environment:以下仅适用于您的本地环境:

Note: Update the command below to match your version postgresql/13.2/...注意:更新下面的命令以匹配您的版本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另外,请确保启动您的服务器> pg_ctl -D /usr/local/var/postgres start

TL;DR; TL; 博士; 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如果您使用 PostgresAPP 而不是 BREW 安装了 Postgres,那么问题可能是您在 $APTH 中没有 postgres bin 文件夹

The solution is to find the Posgres app installation folder an in it the /bin folder.解决方案是在其中找到 Posgres 应用程序安装文件夹和 /bin 文件夹。

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:在我的情况下,如果我运行which postgres不起作用,这意味着我的 $PATH 中没有它,所以我所做的是导航到: cd /Applications/Posgres.app然后到Contents然后到Versions直到我找到latest文件夹:

/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现在,我可以通过提供我的 Postgres 应用程序安装的 bin 文件夹的路径来安装 PG GEM

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:最后,在我的 Rails 项目根目录的终端中,我运行了我向 GEM 安装程序提供 postgres 配置文件路径的地方:

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. Postgresql 需要在本地才能安装 gem pg。 Try this尝试这个

brew install postgresql

and the re-install bundle和重新安装包

bundle install

or If you are using yum.或者如果您使用的是 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.如果您安装了 Cesar Faria 回答中提到的 postgresql-contrib 和 libpq-dev ,并且仍然遇到相同的错误,则很可能您错过了被认为对构建 Debian 软件包至关重要的软件包列表。 All that packages included in build-essential package. build-essential 包中包含的所有包。 So, all you need to do to get rid of the error is the command below.因此,您需要做的就是摆脱错误是下面的命令。

sudo apt install libpq-dev build-essential

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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