【问题标题】:An error occurred while installing mysql (2.9.1) and Bundler cannot continue安装 mysql (2.9.1) 时出错,Bundler 无法继续
【发布时间】:2023-10-17 01:54:01
【问题描述】:

我正在尝试按照本指南将 Rails 应用程序上传到 hostgator: http://support.hostgator.com/articles/specialized-help/technical/how-do-i-start-using-ruby-on-rails 我在第 5.6 点遇到错误。当我这样做时:

rake generate_session_store

它说找不到 gem 'rack' 并建议我运行捆绑安装。当我这样做时:

Gem::Installer:ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... 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/bin/ruby
    --with-mysql-config
    --without-mysql-config

Gem files will remain installed in /home4/agtcorp/ruby/gems/gems/mysql-2.9.1 for inspection.
An error ocurred while installing mysql(2.9.1) and Bundler cannot continue.
Make sure that gem install mysql -v '2.9.1 succeeds before bundling.

我显然试过 gem install mysql -v '2.9.1' 。 我联系了 Hostgator 支持,一位 linux 管理员对我说:

'我看到您的问题是由于声明的路径不正确。 Rakefile 当前位于 /home4/agtcorp/rails_apps/agtcorp2/。也许如果你更新 安装要使用正确的路径,它会在 完整文件路径 /home4/agtcorp/rails_apps/agtcorp2/Rakefile。'

我不知道该怎么做。请帮忙!

【问题讨论】:

  • 第 0 步:寻找一个新的主机,因为 HostGator 对 Rails 的特别支持和对 Ruby 的普遍支持不好。您将全程与他们的基础设施作斗争。

标签: ruby-on-rails ruby rack gemfile


【解决方案1】:

我觉得你缺少“libmysqlclient-dev”,试试看:

   sudo apt-get install mysql-server mysql-client libmysqlclient-dev 

【讨论】:

  • 如果您尝试在本地 linux(debian 类型)系统(不是 HostGator)上捆绑安装时遇到此错误,这可能会解决您的问题。它解决了我的问题。
  • @scottxu 很好的答案。帮助了我。
【解决方案2】:

正如 Srdjan 所说,HostGator 的回答是错误的。问题不在于 Rakefile 的位置——问题在于没有可供您使用的 MySQL 标头。但这最终无关紧要,因为 HostGator 共享主机客户(如大多数共享主机客户)无法访问编译器。

可以为您编译原生 gem 的唯一人是 HostGator 管理员。但是,它们通常不会,因为 HostGator 有一个预定义的(过时的,通常不安全的)允许版本列表。

虽然有可能在 Hostgator 上启动并运行一个非常简单的 Rails 应用程序,但需要付出巨大的努力和麻烦,但像这样的 IaaS 平台可能会为您提供更好的服务如果您对典型的系统管理员职责不满意,则 Heroku 或 AWS、Azure 或 Rackspace 等 PaaS 平台(如果您不满意)。

【讨论】:

    【解决方案3】:

    这个建议很可能是错误的。这里的问题是 mysql gem 没有找到相关的 MySQL C 库。您通常需要使用 --with-opt-dir 和 --with-opt-libs 参数来提供它。

    另一个问题可能是未安装 MySQL 开发库。这是 Hostgator 支持可能需要帮助您解决的问题。

    【讨论】:

    • 你说得对,我请了另一位 Linux 管理员,他为我安装了 gem。