![](/img/trans.png)
[英]Gem::Ext::BuildError: ERROR: Failed to build gem native extension. GCC error
[英]Gem::Ext::BuildError: ERROR: Failed to build gem native extension. on Ubuntu 22.04
我在使用rails new Project --database=postgresql
安裝我的 rails 項目時遇到了這個錯誤 當我嘗試安裝包時,會彈出這些錯誤:
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies.....
Using rake 13.0.6
Using concurrent-ruby 1.1.10
Using racc 1.6.0
Using crass 1.0.6
Using rack 2.2.4
Using minitest 5.16.2
Using builder 3.2.4
Using marcel 1.0.2
Using websocket-extensions 0.1.5
Using digest 3.1.0
Using nio4r 2.5.8
Using mini_mime 1.1.2
Using erubi 1.11.0
Using bindex 0.8.1
Using timeout 0.3.0
Using bundler 2.3.17
Using matrix 0.4.2
Using msgpack 1.5.4
Using public_suffix 4.0.7
Using io-console 0.5.11
Using strscan 3.0.4
Using method_source 1.0.0
Using zeitwerk 2.6.0
Using childprocess 4.1.0
Using rexml 3.2.5
Using thor 1.2.1
Using rubyzip 2.3.2
Using websocket 1.2.9
Using i18n 1.12.0
Using tzinfo 2.0.5
Using nokogiri 1.13.8 (x86_64-linux)
Using rack-test 2.0.2
Using sprockets 4.1.1
Using websocket-driver 0.7.5
Using puma 5.6.4
Using mail 2.7.1
Using net-protocol 0.1.3
Using bootsnap 1.13.0
Using addressable 2.8.0
Using reline 0.3.1
Using regexp_parser 2.5.0
Using activesupport 7.0.3.1
Using loofah 2.18.0
Using net-smtp 0.3.1
Using xpath 3.2.0
Using irb 1.4.1
Using net-imap 0.2.3
Using selenium-webdriver 4.4.0
Using rails-dom-testing 2.0.3
Using activemodel 7.0.3.1
Using rails-html-sanitizer 1.4.3
Using capybara 3.37.1
Using net-pop 0.1.1
Using globalid 1.0.0
Using activerecord 7.0.3.1
Using actionview 7.0.3.1
Using debug 1.6.2
Using actionpack 7.0.3.1
Using webdrivers 5.0.0
Using jbuilder 2.11.5
Using activejob 7.0.3.1
Using actioncable 7.0.3.1
Using activestorage 7.0.3.1
Using railties 7.0.3.1
Using actionmailbox 7.0.3.1
Using actiontext 7.0.3.1
Using actionmailer 7.0.3.1
Using importmap-rails 1.1.5
Using stimulus-rails 1.1.0
Using turbo-rails 1.1.1
Using web-console 4.2.0
Using sprockets-rails 3.4.2
Using rails 7.0.3.1
安裝帶有原生擴展的 pg 1.4.3 Gem::Ext::BuildError: ERROR: Failed to build gem native extension。
current directory:
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.3/ext
/home/christian/.rbenv/versions/3.1.2/bin/ruby -I
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0 -r
./siteconf20220811-57965-mz3s1i.rb extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... yes
Using config values from /usr/bin/pg_config
Using libpq from /usr/lib/x86_64-linux-gnu
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*****************************************************************************
Unable to find PostgreSQL client library.
Please install libpq or postgresql client package like so:
sudo apt install libpq-dev
sudo yum install postgresql-devel
sudo zypper in postgresql-devel
sudo pacman -S postgresql-libs
or try again with:
gem install pg -- --with-pg-config=/path/to/pg_config
or set library paths manually with:
gem install pg -- --with-pg-include=/path/to/libpq-fe.h/
--with-pg-lib=/path/to/libpq.so/
*** 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=/home/christian/.rbenv/versions/3.1.2/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-gvl-unlock
--disable-gvl-unlock
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/pg-1.4.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.3 for
inspection.
Results logged to
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/pg-1.4.3/gem_make.out
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:95:in
`run'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:47:in
`block in build'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tempfile.rb:317:in `open'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:26:in
`build'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:161:in
`build_extension'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:195:in
`block in build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in
`each'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in
`build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/installer.rb:853:in
`build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/rubygems_gem_installer.rb:71:in
`build_extensions'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/source/rubygems.rb:209:in
`install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/gem_installer.rb:54:in
`install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/parallel_installer.rb:186:in
`do_install'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/installer/parallel_installer.rb:177:in
`block in worker_pool'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:62:in
`apply_func'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:57:in
`block in process_queue'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:54:in
`loop'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:54:in
`process_queue'
/home/christian/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.17/lib/bundler/worker.rb:91:in
`block (2 levels) in create_threads'
安裝pg(1.4.3)時出錯,Bundler無法繼續
.
In Gemfile:
pg
最重要的是,項目的回購已創建但沒有Gemfile.lock
我的計算機上安裝了 PostgreSQL。 我正在使用Ubutu 22.04.1
我已經嘗試了很多建議但仍然找不到出路。 如果有人能提供幫助,我將不勝感激。
運行以下命令
gem install pg -v '1.4.3'
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev postgresql-client-common postgresql-client libpq-dev
這是我在計算機中修復此問題的方法。
首先嘗試安裝 libpq-dev sudo apt-get install libpq-dev
然后計算機會抱怨不兼容的 libpq5 版本:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libpq-dev : Depends: libpq5 (= 14.5-0ubuntu0.22.04.1) but 14.5-1.pgdg20.04+1 is to be installed
E: Unable to correct problems, you have held broken packages.
這意味着您擁有比 libpq5-dev 要求的版本更新的 libpq 版本。 安裝正確的 libpq5 版本:
sudo apt-get install libpq5=14.5-0ubuntu0.22.04.1
然后嘗試再次安裝 libpq-dev
sudo apt-get install libpq-dev
您現在應該可以進行捆綁安裝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.