无法在Ubuntu 14上安装mysql2 gem

时间:2014-08-27 00:55:13

标签: mysql ruby-on-rails ruby rubygems

我正在运行Ubuntu 14,当我尝试运行rails server时,我收到此错误:

  

在此机器上可用的宝石中找不到宝石'mysql2(> = 0)ruby'。   运行bundle install以安装缺少的宝石。

所以我运行bundle install然后我收到以下错误。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/mysql2-0.3.16 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.

所以我运行gem install mysql2 -v '0.3.16'并成功安装,但是当我再次运行bundle install时,它会给我同样的错误:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/mysql2-0.3.16 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.

1 个答案:

答案 0 :(得分:0)

从头再次开始,这次你应该安装RVM,因为它非常善于为你处理所有这些东西。 http://rvm.io/rvm/install

确保首先获得所有依赖项,此代码将检查您拥有和不具备的内容:

for name in {bash,awk,sed,grep,ls,cp,tar,curl,gunzip,bunzip2,git,svn} ; do which $name ;  done

还值得查看先决条件页面:http://rvm.io/rvm/prerequisites

您可以运行以下代码,使用Ruby 2.1.1和Rails安装rv:

\curl -sSL https://get.rvm.io | bash -s stable --rails

然后开始使用RVM:

/bin/bash --login

它绝对值得使用RVM,它可以让您在管理ruby版本,宝石等时更轻松,只需确保您通读网页以便了解如何使用它。