gem安裝軟件時遇到的問題以及解決思路
阿新 • • 發佈:2017-10-28
gem安裝包出錯
今天需要在由於工作需要,需要使用bundle install來更新依賴包,本以為很順利,結果遇到了下面的一堆問題,在此進行記錄並分享自己遇到這個問題時的思路:
問題一:用gem安裝ruby的包時出錯
root@kali:~/Desktop# gem install nokogiri -v ‘1.6.8.1‘ Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.6.8.1/ext/nokogiri /usr/bin/ruby2.3 -r ./siteconf20171027-10596-epcpmc.rb extconf.rb checking if the C compiler accepts ... yes Building nokogiri using packaged libraries. Using mini_portile version 2.1.0 checking for gzdopen() in -lz... no zlib is missing; necessary for building libxml2 *** 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=/usr/bin/$(RUBY_BASE_NAME)2.3 --help --clean --use-system-libraries --enable-static --disable-static --with-zlib-dir --without-zlib-dir --with-zlib-include --without-zlib-include=${zlib-dir}/include --with-zlib-lib --without-zlib-lib=${zlib-dir}/lib --enable-cross-build --disable-cross-build To see why this extension failed to compile, please check the mkmf.log which can be found here: /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /var/lib/gems/2.3.0/gems/nokogiri-1.6.8.1 for inspection. Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/gem_make.out
問題描述:
gem開始嘗試安裝,然後依次出現以下錯誤: 1.安裝nokogiri失敗; 2.構建gem本地拓展失敗; 然後,gem開始檢查為什麽失敗: 1.checking if the C compiler accepts ... yes 2.checking for gzdopen() in -lz... no 在這裏發現問題,於是gem給出失敗的原因: zlib is missing; necessary for building libxml2 所以說,問題的根據點在於如何安裝zlib。
思路:(系統為Linux)
1.直接啃錯誤信息,不要慫就是看。經過翻譯之後發現直接原因是gzdopen()函數沒有,這個函數沒有 是因為缺少了一個包:zlib,錯誤描述為:zlib is missing; necessary for building libxml2。根 據Linux的一貫作風,缺什麽裝什麽就行。 2.發現原因之後,可以直接去百度當前系統如何安裝zlib,但是,因為我有apt-get可以使用,於是, 直接上:apt-get install zlib加tag減,看一下都有哪些與zlib有關的可以直接安裝的東西,發現了4 個:zlib1g zlib1g-dbg zlib1g-dev zlibc 因為我這裏需要調用zlib中的內容,本能的安裝開發者包:zliblg-dev: apt-get install zliblg-dev 然後發現,問題被巧妙的解決了。
問題二:用gem安裝Ruby包又出錯了
root@kali:~/Desktop# gem install pg -v ‘0.20.0‘ Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.3.0/gems/pg-0.20.0/ext /usr/bin/ruby2.3 -r ./siteconf20171026-3597-1h17ktg.rb extconf.rb checking for pg_config... yes Using config values from /usr/bin/pg_config You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. 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=/usr/bin/$(RUBY_BASE_NAME)2.3 --with-pg --without-pg --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: /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.20.0/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /var/lib/gems/2.3.0/gems/pg-0.20.0 for inspection. Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.20.0/gem_make.out
解決方案:(這裏的問題與上面的類似,於是先采用類似的方案嘗試解決。最終解決方案如下)
apt-get install libpq-dev
問題三:強大的gem
root@kali:~/Desktop# gem install sqlite3 -v ‘1.3.13‘ Building native extensions. This could take a while... ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3 /usr/bin/ruby2.3 -r ./siteconf20171026-6745-18q3rtn.rb extconf.rb checking for sqlite3.h... no sqlite3.h is missing. Try ‘brew install sqlite3‘, ‘yum install sqlite-devel‘ or ‘apt-get install libsqlite3-dev‘ and check your shared library search path (the location where your sqlite3 shared library is located). *** 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=/usr/bin/$(RUBY_BASE_NAME)2.3 --with-sqlite3-config --without-sqlite3-config --with-pkg-config --without-pkg-config --with-sqlite3-dir --without-sqlite3-dir --with-sqlite3-include --without-sqlite3-include=${sqlite3-dir}/include --with-sqlite3-lib --without-sqlite3-lib=${sqlite3-dir}/lib To see why this extension failed to compile, please check the mkmf.log which can be found here: /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /var/lib/gems/2.3.0/gems/sqlite3-1.3.13 for inspection.
解決方案:
這個例子中,有意思的地方在於gem不僅告訴你出現問題的原因,還給出了解決方案: sqlite3.h is missing. Try ‘brew install sqlite3‘,‘yum install sqlite-devel‘ or ‘apt-get install libsqlite3-dev‘ and check your shared library search path (the location where your sqlite3 shared library is located). 這裏給我的經驗就是,一定要直接讀錯誤信息,一定要讀,一定要讀。
本文出自 “execute” 博客,請務必保留此出處http://executer.blog.51cto.com/10404661/1976896
gem安裝軟件時遇到的問題以及解決思路