我正在运行 Ubuntu 14,当我尝试运行 rails server
但出现此错误时:
Could not find gem 'mysql2 (>= 0) ruby' in the gems available on this machine. Run
bundle install
to install missing gems.
因此,我运行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.
最佳答案
从头开始,这次您应该安装 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 安装 rvm:
\curl -sSL https://get.rvm.io | bash -s stable --rails
然后开始使用 RVM:
/bin/bash --login
使用 RVM 绝对值得,它会让您在管理 ruby 版本、gems 等时变得更加轻松,只需确保您通读网页,以便知道如何使用它。
关于mysql - 在 Ubuntu 14 上安装 mysql2 gem 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25517328/