[英]unable to install pg gem
我嘗試使用gem install pg
但它似乎不起作用。
gem install pg
給出了這個錯誤
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
C:/Ruby/bin/ruby.exe 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=C:/Ruby/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1 for
inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1/ext/gem_make.out
我遇到了這個問題,這對我有用:
安裝 postgresql-devel 包,這將解決 pg_config 丟失的問題。
sudo apt-get install libpq-dev
問題是 gem 依賴,所以在安裝 pg 之前確保你已經安裝了“libpq-dev”
Ubuntu系統:
須藤 apt-get 安裝 libpq-dev
RHEL系統:
yum 安裝 postgresql-devel
馬克:
brew 安裝 postgresql
gem install pg -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
@Winfield說過:
pg gem 需要綁定 postgresql 客戶端庫。 此錯誤通常意味着它找不到您的 Postgres 庫。 要么您沒有安裝它們,要么您可能需要將
--with-pg-dir=
傳遞給您的 gem 安裝。
不僅如此,您只需要--with-pg-config=
即可安裝它。
如果有任何機會,您還通過 mac 上的網站包安裝了 postgres,它將位於/Applications/Postgres.app/Contents/Versions/9.3/bin
地方。
所以,要么你把它傳遞給 gem 安裝:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
或者您正確設置了 PATH 。 由於這可能太多,暫時設置PATH:
export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
我沒有安裝 postgresql,所以我只是使用
sudo apt-get install postgresql postgresql-server-dev-9.1
在 Ubuntu 12.04 上。
這解決了它。
更新:
使用最新版本:
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3
這在我的情況下有效:
sudo apt-get install libpq-dev
我用過:
如果你在 Mac 上使用Postgres.app ,你可以像這樣一勞永逸地解決這個問題:
首先gem uninstall pg
,然后編輯您的~/.bash_profile
或~/.zshrc
文件或等效文件並添加:
# PostgreSQL bin path
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
然后bundle install
和gem install pg
都應該按預期工作。
在這里回答: 無法在 Windows 上安裝 pg gem
昨天發布的最新版本的 pg (0.10.0) 沒有 Windows 本地版本,但是如果您安裝 0.9.0,它應該可以毫無問題地安裝二進制文件。
$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg
將 9.1 替換為您系統上安裝的版本。
在 macOS (El Capitan) 上。 您可以簡單地使用: brew install postgresql
對於 Mac 用戶
PATH=$PATH:/Library/PostgreSQL/9.4/bin/ gem install pg
這應該可以解決問題
與ARCH
標志一起使用。
sudo env ARCHFLAGS="-arch x86_64" gem install pg
這解決了您遇到的相同問題。
pg gem 需要綁定 postgresql 客戶端庫。 此錯誤通常意味着它找不到您的 Postgres 庫。 要么您沒有安裝它們,要么您可能需要將 --with-pg-dir= 傳遞給您的 gem 安裝。
卸載然后重新安裝postgresql-client
libpq5
libpq-dev
sudo apt remove postgresql-client libpq5 libpq-dev
sudo apt install postgresql-client libpq5 libpq-dev
然后再次安裝pg
gem 指向/usr/lib
以找到pg
庫:
gem install pg -- --with-pg-lib=/usr/lib
輸出(你應該在上一個命令之后看到的):
Building native extensions with: '--with-pg-lib=/usr/lib'
This could take a while...
Successfully installed pg-1.2.3
Parsing documentation for pg-1.2.3
Installing ri documentation for pg-1.2.3
Done installing documentation for pg after 1 seconds
1 gem installed
Gem 應該安裝,然后繼續正常的bundle
安裝或更新:
bundle
bundle install
bundle update
我在 Linux Mint (Maya) 13 上解決了這個問題,我通過安裝 postgresql 和 postgresql-server 修復了它:
apt-get install postgresql-9.1
sudo apt-get install postgresql-server-dev-9.1
無論您運行的是什么操作系統,請查看"Makefile"
的日志文件以了解發生了什么,而不是盲目安裝東西。
在我的情況下,MAC OS,日志文件在這里:
/Users/za/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-1.0.0/mkmf.log
日志表明無法創建 make 文件,原因如下:
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers
在 mkmf.log 中,您將看到它無法找到所需的庫以完成構建。
checking for pg_config... no
Can't find the 'libpq-fe.h header
blah blah
運行"brew install postgresql"
,我可以看到所有必需的庫都在那里:
za:myapp za$ cat /Users/za/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-1.0.0/mkmf.log | grep yes
find_executable: checking for pg_config... -------------------- yes
find_header: checking for libpq-fe.h... -------------------- yes
find_header: checking for libpq/libpq-fs.h... -------------------- yes
find_header: checking for pg_config_manual.h... -------------------- yes
have_library: checking for PQconnectdb() in -lpq... -------------------- yes
have_func: checking for PQsetSingleRowMode()... -------------------- yes
have_func: checking for PQconninfo()... -------------------- yes
have_func: checking for PQsslAttribute()... -------------------- yes
have_func: checking for PQencryptPasswordConn()... -------------------- yes
have_const: checking for PG_DIAG_TABLE_NAME in libpq-fe.h... -------------------- yes
have_header: checking for unistd.h... -------------------- yes
have_header: checking for inttypes.h... -------------------- yes
checking for C99 variable length arrays... -------------------- yes
多年來,我一直在使用 PG 遇到這個煩人的問題。 我創建了這個要點來提供幫助。
以下命令始終對我有用。
# Substitute Postgres.app/Contents/Versions/9.5 with appropriate version number
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
我必須在 CentOS 5.8 上執行此操作。 運行bundle install
一直導致問題,因為我無法強制它使用特定的 PG 版本。
由於依賴性問題,我也無法yum erase postgresql postgresql-devel
(它會刪除 php、http 等)
解決辦法? 暫時混亂 $PATH 以優先更新 pgsql 而不是默認的更新:
export PATH=/usr/pgsql-9.2/bin:$PATH
bundle install
基本上,使用上述命令,它會在/usr/bin/pg_config
之前查看/usr/pgsql-9.2/bin/pg_config
如果您使用 jruby 而不是 ruby,則在安裝 pg gem 時會遇到類似的問題。 相反,您需要安裝適配器:
gem 'activerecord-jdbcpostgresql-adapter'
在 Mac 上brew install postgres
THEN bundle install
你去這里看看你的pg版本是否支持Win32平台,然后用這個命令安裝:
gem install pg -v 0.14.1 --platform=x86-mingw32
我在 Linux (Pop_OS) 20.10 上使用 Ruby(和其他)的版本管理器( asdf
),並在嘗試了一百萬種不同的方式對其進行排序后,包括上述所有內容
TLDR
gem install pg -v '1.2.3' -- --with-pg-config='/home/username/.asdf/installs/postgres/12.6/bin/pg_config'
找到正確版本的PG安裝,指向bin目錄下的pg_config
如果您使用asdf
安裝postgres
,只需像這樣安裝pg
gem:
asdf global postgres <version>
gem install pg
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.