2013-01-05 99 views
15

我一直試圖在我的Ubuntu 12.04服務器上安裝Gitlab很長一段時間,一切順利,直到我運行bundle installMySQL2寶石將不會安裝

它說它無法安裝MySQL2,但沒有理由或糾正措施。

home/gitlab/gitlab$ sudo -u gitlab -H bundle install --deployment --without development test postgres 
Fetching gem metadata from http://rubygems.org/....... 
Fetching gem metadata from http://rubygems.org/.. 
Using rake (10.0.1) 
Using i18n (0.6.1) 
Using multi_json (1.3.7) 
Using activesupport (3.2.9) 
Using builder (3.0.4) 
Using activemodel (3.2.9) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.1) 
Using actionpack (3.2.9) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.9) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.9) 
Using activeresource (3.2.9) 
Using bundler (1.2.3) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.9) 
Using rails (3.2.9) 
Using acts-as-taggable-on (2.3.3) 
Using backports (2.6.5) 
Using bcrypt-ruby (3.0.1) 
Using blankslate (3.1.2) 
Using sass (3.2.3) 
Using bootstrap-sass (2.2.1.1) 
Using carrierwave (0.7.1) 
Using charlock_holmes (0.6.9) 
Using chosen-rails (0.9.8) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using coffee-rails (3.2.2) 
Using colored (1.2) 
Using daemons (1.1.9) 
Using orm_adapter (0.4.0) 
Using warden (1.2.1) 
Using devise (2.1.2) 
Using diff-lcs (1.1.3) 
Using draper (0.18.0) 
Using escape_utils (0.2.4) 
Using eventmachine (1.0.0) 
Using multipart-post (1.1.5) 
Using faraday (0.8.4) 
Using ffaker (1.15.0) 
Using sass-rails (3.2.5) 
Using font-awesome-sass-rails (2.0.0.0) 
Using foreman (0.60.2) 
Using gemoji (1.2.1) 
Using git (1.2.5) 
Using posix-spawn (0.3.6) 
Using yajl-ruby (1.1.0) 
Using pygments.rb (0.3.2) from https://github.com/gitlabhq/pygments.rb.git (at master) 
Using github-linguist (2.3.4) 
Using github-markup (0.7.4) 
Using gitlab_meta (4.0) 
Using gratr19 (0.4.4.1) 
Using grit (2.5.0) from https://github.com/gitlabhq/grit.git (at 7f35cb9) 
Using hashery (1.5.0) 
Using gitolite (1.1.0) 
Using grack (1.0.0) from https://github.com/gitlabhq/grack.git (at ba46f3b) 
Using hashie (1.2.0) 
Using multi_xml (0.5.1) 
Using rack-accept (0.4.5) 
Using rack-mount (0.8.3) 
Using virtus (0.5.2) 
Using grape (0.2.2) 
Using grit_ext (0.6.1) from https://github.com/gitlabhq/grit_ext.git (at 8e6afc2) 
Using haml (3.1.7) 
Using haml-rails (0.3.5) 
Using httparty (0.9.0) 
Using httpauth (0.2.0) 
Using jquery-atwho-rails (0.1.7) 
Using jquery-rails (2.1.3) 
Using jquery-ui-rails (2.0.2) 
Using jwt (0.1.5) 
Using kaminari (0.14.1) 
Using kgio (2.7.4) 
Using libv8 (3.3.10.4) 
Using modernizr (2.6.2) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. 

     /usr/local/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes 
checking for rb_wait_for_single_fd()... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lm... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lz... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lsocket... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lnsl... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lmygcc... no 
checking for mysql_query() in -lmysqlclient... no 
*** 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/local/bin/ruby 
    --with-mysql-config 
    --without-mysql-config 
    --with-mysql-dir 
    --without-mysql-dir 
    --with-mysql-include 
    --without-mysql-include=${mysql-dir}/include 
    --with-mysql-lib 
    --without-mysql-lib=${mysql-dir}/lib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-mlib 
    --without-mlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-zlib 
    --without-zlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-socketlib 
    --without-socketlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-nsllib 
    --without-nsllib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-mygcclib 
    --without-mygcclib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 


Gem files will remain installed in /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11 for inspection. 
Results logged to /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/ext/mysql2/gem_make.out 
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue. 
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling. 
[email protected]:/home/gitlab/gitlab$ 
+2

'mkmf.log'文件說了什麼? – rudolph9

+0

你安裝了mysql-server嗎? – apchester

+0

這可能有所幫助:http://stackoverflow.com/questions/4613116/difficulties-installing-mysql-gem-on-ubuntu – Zabba

回答

51

它告訴你一個通用的可能出現的問題:

不能由於某種原因創建的Makefile,可能缺乏必要的 庫和/或標題。檢查mkmf.log文件以獲取更多 的詳細信息。您可能需要配置選項。

這是你的線索。

確保您已安裝MySQL客戶端回購以及相關的「devel」軟件包。 Ruby,Python,Perl等語言需要安裝庫和頭文件,以便它們可以編譯提供從語言到驅動程序接口的本機模塊。

此外,你需要mysql_config,這是由安裝:

sudo apt-get install libmysqlclient-dev 

我能夠用我的Ubuntu VM複製您的問題,並安裝的libmysqlclient-dev的後固定。

它將mysql_config放置在/usr/bin/mysql_config中,並且gem install mysqlgem install mysql2都能夠成功安裝。

+1

而且如果你將mysql安裝在一個完全不同的服務器上,你會怎樣?仍然需要在運行rvm和rails的服務器上安裝所有這些軟件包? – JohnMerlino

+0

MySQL,PostgreSQL或其他客戶端/服務器應用程序有兩部分;客戶端軟件和服務器軟件。如果您在另一臺計算機上並且想要編寫代碼與服務器交談,那麼,是的,您必須安裝客戶端代碼。如果代碼無法訪問服務器的客戶端驅動程序,您的代碼如何與服務器通信? –

+1

我在MBP上遇到了同樣的問題,但您的回答幫助我解決了問題。運行'brew install mysql'後,我能夠成功運行'gem instal mysql2'。 – shovavnik

11

謝謝你,它的工作,只好只是添加了一些額外的東西

sudo apt-get install libmysqld-dev libmysqlclient-dev mysql-client 
+0

你說這個解決方案適合你,但你沒有給它支票?你能接受他的回答嗎? – DutGRIFF

3

我已經使用在rails4該解決方案針對此問題:(Ubuntu的12.04)

1) Install MySQL from symptic manager just type "mysql-server-5.5" 
    2) use following command and install 
     sudo apt-get install mysql-client libmysqlclient-dev 
0

如果你是使用Windows 8 + x64,請看這個問題正文中提供的答案:

Installing MySQL2 Gem on Windows

編輯

爲了downvoters開心,我複製鏈接的問題的內容:

  1. 清理:你在這裏的原因是,你可能是試圖用 來安裝這個gem,並且它已經失敗了,所以你有一些清理到 的辦法:gem卸載mysql2

  2. Downloa d紅寶石2。0的64位的Windows:

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353-x64.exe?direct

  • 運行安裝程序。請注意它安裝的目錄,並確保它位於用戶路徑中。去

    Control Panel > System and Security > System - Advanced System Settings > Environment Variables 
    
  • 做出紅寶石安裝目錄下的bin目錄確保路徑是在本地用戶的PATH環境變量(這也是確定的,如果它在系統PATH環境變量)

  • 下載紅寶石2 64位的開發工具包:
  • http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe

    1. 運行安裝程序並記下安裝目錄的位置。說明指出,一旦完成安裝,您需要運行devkitvars.bat文件來設置環境變量。這不適用於Windows 8.1。您需要重複說明以設置上面#2中描述的本地路徑,爲本地用戶設置路徑環境變量以添加ruby開發工具箱bin目錄以及ruby dev工具包mingw bin目錄。例如,如果開發套件安裝到c:\ ruby​​2devkit,並安裝ruby2到C:\ Ruby200-x64的目錄,那麼你的編輯你的路徑語句看起來像這樣:

      C:\Ruby200-x64\bin;C:\ruby2-devkit\bin;c:\ruby2-devkit\mingw\bin 
      
    2. 接下來你需要安裝mysql連接器。請勿下載並運行自行安裝程序。相反,請下載zip文件並將其解壓縮。注意:您解壓它(這個職位的目的,目錄,讓我們假設你把它解壓到c:\ mysql的連接器:

    http://dev.mysql.com/downloads/file.php?id=450612

  • MySQL Connector 64位中包含的libmysql.lib與mingw64-gcc編譯器不兼容。您需要生成兼容mingw64的libmysql.lib文件。

  • 和下載工具,你需要

    https://structure-svm-map.googlecode.com/files/svm-map-win.zip

  • 此文件解壓到本地目錄,讓我們假設您解壓縮它到c:\ SVM-地圖

  • 編輯PATH環境如前所述,現在看起來像這樣:

    C:\Ruby200-x64\bin;C:\ruby2-devkit\bin;c:\ruby2-devkit\mingw\bin;c:\svm-map;C:\svm-map\python-mingw-lib 
    
  • G enerate新的MySQL庫:

    cd c:\mysql-connector\lib 
    
    gendef.exe libmysql.dll 
    
    dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib 
    
    copy libmysql.dll C:\Ruby200-x64\bin 
    
    copy libmysql.lib C:\Ruby200-x64\bin 
    
  • 安裝寶石如下(注意使用正斜線而非反斜線,如果你用反斜槓它會失敗):

    gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-connector/"' 
    
  • 希望這有助於,並希望有人會關注那些想要進行Ruby on Rails開發的少數​​Windows 7/8.1用戶。