如何在 Ubuntu 16.04 上安装 mysql2 [错误:安装 mysql2 时出错:错误:无法构建 gem 本机扩展。] [重复]
Posted
技术标签:
【中文标题】如何在 Ubuntu 16.04 上安装 mysql2 [错误:安装 mysql2 时出错:错误:无法构建 gem 本机扩展。] [重复]【英文标题】:How to install mysql2 on Ubuntu 16.04 [ ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.] [duplicate] 【发布时间】:2016-09-11 11:08:00 【问题描述】:我不知道在 ubuntu 上安装 mysql2 :(
sudo gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
/usr/bin/ruby2.3 -r ./siteconf20160515-9715-1s2u1sj.rb 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.3.0/gems/mysql2-0.4.4 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.4.4/gem_make.out
sudo apt-get install libmysqlclient-dev
Lendo listas de pacotes... Pronto
Construindo árvore de dependências
Lendo informação de estado... Pronto
libmysqlclient-dev is already the newest version (5.7.12-0ubuntu1).
0 pacotes atualizados, 0 pacotes novos instalados, 0 a serem removidos e 61 não atualizados.
但不工作
【问题讨论】:
rake testCould not find gem 'mysql2 (< 0.5, >= 0.3.13)' in any of the gem sources listed in your Gemfile or available on this machine.
运行 bundle install
以安装缺失的 gem。
你安装了 ruby 开发环境吗? sudo apt-get install ruby-dev
检查您是否具备构建 mysql2 gem 的本机扩展的所有其他要求。
***.com/questions/3608287/…
【参考方案1】:
首先,安装 libmysqlclient-dev 使用:
sudo apt-get install libmysqlclient-dev
然后:
bundle
【讨论】:
【参考方案2】:sudo apt-get install ruby-mysql2
【讨论】:
虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高答案的长期价值。 这种方式是安装“ruby-mysql2”操作系统包,可能会导致安装错误或太旧的版本(取决于操作系统)【参考方案3】:sudo apt-get install libnetcdf-dev libssl-dev libcrypto++-dev libgmp-dev
为我解决了同样的问题
【讨论】:
以上是关于如何在 Ubuntu 16.04 上安装 mysql2 [错误:安装 mysql2 时出错:错误:无法构建 gem 本机扩展。] [重复]的主要内容,如果未能解决你的问题,请参考以下文章
如何在 linux ubuntu 16.04 上安装 SDK 管理器?
text 如何在Ubuntu 16.04上安装GeckoDriver
markdown 如何在ubuntu 16.04上安装虚拟环境
如何在 ubuntu 16.04 机器上安装和配置 HSQL DB