MySQL gem install:无法构建gem本机扩展(找不到头文件)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4304438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gem install: Failed to build gem native extension (can't find header files)
提问by Tim
I am using Fedora 14 and I have MySQL and MySQL server 5.1.42 installed and running. Now I tried to do this as root user:
我正在使用 Fedora 14,并且安装并运行了 MySQL 和 MySQL 服务器 5.1.42。现在我尝试以 root 用户身份执行此操作:
gem install mysql
But I get this error:
但我收到此错误:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
What's wrong here? In installed ruby 1.8.7. and the latest rubygems 1.3.7.
这里有什么问题?在安装的 ruby 1.8.7 中。以及最新的 rubygems 1.3.7。
回答by Brian Lacy
For those who may be confused by the accepted answer, as I was, you also need to have the ruby headers installed [ruby-devel].
对于那些可能对接受的答案感到困惑的人,就像我一样,您还需要安装 ruby 头文件 [ ruby-devel]。
The article that saved my hide is here.
拯救我的隐藏的文章在这里。
And this is the revised solution (note that I'm on Fedora 13):
这是修订后的解决方案(请注意,我使用的是 Fedora 13):
yum -y install gcc mysql-devel ruby-devel rubygems
gem install -y mysql -- --with-mysql-config=/usr/bin/mysql_config
For Debian, and other distributions using Debian style packaging the ruby development headers are installed by:
对于 Debian 和其他使用 Debian 风格打包的发行版,ruby 开发头文件通过以下方式安装:
sudo apt-get install ruby-dev
For Ubuntu the ruby development headers are installed by:
对于 Ubuntu,ruby 开发头文件通过以下方式安装:
sudo apt-get install ruby-all-dev
If you are using a earlier version of ruby (such as 2.2), then you will need to run:
如果您使用的是较早版本的 ruby(例如 2.2),则需要运行:
sudo apt-get install ruby2.2-dev
(where 2.2 is your desired Ruby version)
(其中 2.2 是您想要的 Ruby 版本)
回答by Nowaker
Red Hat, Fedora:
红帽、Fedora:
yum -y install gcc mysql-devel ruby-devel rubygems
gem install -y mysql -- --with-mysql-config=/usr/bin/mysql_config
Debian, Ubuntu:
Debian、Ubuntu:
apt-get install libmysqlclient-dev ruby-dev
gem install mysql
Arch Linux:
拱形Linux:
pacman -S libmariadbclient
gem install mysql
回答by Dror S.
For anyone reading this in 2015: if you happened to install the package ruby2.0, you need to install the matching ruby2.0-devto get the appropriate Ruby headers. The same goes for ruby2.1and ruby2.2, etc. For example:
对于在 2015 年阅读本文的任何人:如果您碰巧安装了 package ruby2.0,则需要安装匹配ruby2.0-dev以获取适当的 Ruby 标头。这同样适用于ruby2.1和ruby2.2等。例如:
$ sudo apt-get install ruby2.2-dev
回答by andrej
it seems that the
似乎
yum install ruby-devel
was enough for me to perform
足以让我表演
gem install datamapper
afterwards.
然后。
It's possible that you will need to install another packages:
您可能需要安装其他软件包:
yum install gcc gcc-c++
to be able to build native extensions
能够构建本机扩展
回答by Ajit Singh
MAC users may face this issue when xcode tools are not installed properly. Below is the command to get rid of the issue.
当 xcode 工具没有正确安装时,MAC 用户可能会遇到这个问题。下面是摆脱这个问题的命令。
xcode-select --install
回答by Tim
回答by qkrijger
This post helped me. Thanks a lot.
这篇文章帮助了我。非常感谢。
On Linux (Ubuntu 12.10) I needed to run
在 Linux (Ubuntu 12.10) 上我需要运行
sudo apt-get install ruby
sudo apt-get install rubygems
sudo apt-get install ruby-dev
before I could succesfully run
在我成功运行之前
sudo gem install jekyll
回答by Hafiz Shehbaz Ali
If you have gem installed and ruby and not able to install rails, then install ruby dev lib.
如果您安装了 gem 和 ruby,但无法安装 rails,请安装 ruby dev lib。
sudo apt-get install ruby-dev
It works for me. I have tried the different solution.
这个对我有用。我尝试了不同的解决方案。
回答by Mike
For those that are still experiencing problems, like I have(I am using Ubuntu 16.04), I had to put in the following commands in order to get some gems like bcrypt, pg, and others installed. They are all similar to the ones above except for one.
对于那些仍然遇到问题的人,就像我一样(我使用的是 Ubuntu 16.04),我必须输入以下命令才能安装 bcrypt、pg 和其他一些 gem。除了一个之外,它们都与上面的相似。
sudo apt-get install ruby-dev -y
sudo apt-get install libpq-dev -y
sudo apt-get install libmysqlclient-dev
sudo apt-get install build-essential patch -y
This allowed me to install gems like, PG, bcrypt, and recaptcha.
这让我可以安装像 PG、bcrypt 和 recaptcha 这样的 gem。
回答by mkungla
Red Hat, Fedora:
红帽、Fedora:
sudo dnf -y install gcc-c++ redhat-rpm-config ruby-devel gcc mysql-devel rubygems

