【问题标题】:mysql2 gem not loaded installing redmine-agilemysql2 gem 未加载安装 redmine-agile
【发布时间】:2019-07-06 13:21:55
【问题描述】:

我正在尝试安装Redmine Agile plugin,但无法通过第 4 步:

/var/www/html/redmine$ sudo bundle exec rake redmine:plugins NAME=redmine_agile RAILS_ENV=production
(in /usr/share/redmine)
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/usr/share/redmine/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `eval'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `each'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/usr/share/redmine/config/environment.rb:14:in `<top (required)>'
/usr/share/redmine/lib/tasks/redmine.rake:52:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'

Caused by:
Gem::LoadError: mysql2 is not part of the bundle. Add it to your Gemfile.
/var/lib/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/usr/share/redmine/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `eval'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `each'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/usr/share/redmine/config/environment.rb:14:in `<top (required)>'
/usr/share/redmine/lib/tasks/redmine.rake:52:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => redmine:plugins:migrate => environment
(See full trace by running task with --trace)

我以前无法sudo gem install mysql2,但通过关注this answer 解决了这个问题。

我确实尝试添加 gem "mysql2",但这并没有解决问题。

/var/www/html/redmine$ cat plugins/redmine_agile/Gemfile
gem "redmine_crm"
gem "mysql2"

我不确定and ensure its version is at the minimum required by ActiveRecord 是什么意思。我不确定如何检查那是什么。我知道我可以在 Gemfile 中设置 gem 的版本,但我不知道它会被设置为什么。

我使用的是 Ubuntu 16.04.4 LTS、MySQL 5.7.22。我正在使用 similar to this answer 为 Redmine 服务。

更新

当我尝试将rake 设置为www-data 时,我得到的错误更改为

www-data@host:/usr/share/redmine/public/plugins/redmine_agile$ bundle exec rake redmine:plugins NAME=redmine_agile RAILS_ENV=production
`/home/ubuntu` is not writable.
Bundler will use `/tmp/bundler/home/ubuntu' as your home directory temporarily.
Could not find gem 'redmine_crm' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.

(尝试从/var/www/html/redminerake 不断让我收到mysql2 错误。)

然后我尝试安装redmine_crm。我不能以www-data 的身份执行此操作,所以我以 root 身份执行此操作:

/var/www/html/redmine/plugins/redmine_agile$ sudo gem install redmine_crm

然后我尝试了bundle install,但得到了

There was an error while trying to write to
`/usr/share/redmine/public/plugins/redmine_agile/Gemfile.lock`. It is likely that you need to grant
write permissions for that path.

所以我以 root 身份运行它。

/var/www/html/redmine/plugins/redmine_agile$ sudo bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as
root will break this application for all non-root users on this machine.
Resolving dependencies...
Using rake 12.3.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 4.2.6
Using builder 3.2.3
Using erubis 2.7.0
Using nokogiri 1.6.7.2
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.6
Using crass 1.0.4
Using loofah 2.2.2
Using rails-html-sanitizer 1.0.4
Using actionview 4.2.6
Using rack 1.6.4
Using rack-test 0.6.3
Using actionpack 4.2.6
Using globalid 0.4.1
Using activejob 4.2.6
Using mini_mime 1.0.0
Using mail 2.7.0
Using actionmailer 4.2.6
Using activemodel 4.2.6
Using arel 6.0.3
Using activerecord 4.2.6
Using bundler 1.16.2
Using concurrent-ruby 1.0.5
Using liquid 2.6.3
Using mysql2 0.5.2
Using thor 0.20.0
Using railties 4.2.6
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 4.2.6
Using redmine_crm 0.0.42
Bundle complete! 2 Gemfile dependencies, 37 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

尝试rake 然后又给我一个不同的错误。

ubuntu@host:/var/www/html/redmine/plugins/redmine_agile$ sudo bundle exec rake redmine:plugins NAME=redmine_agile RAILS_ENV=production
(in /usr/share/redmine)
rake aborted!
NameError: uninitialized constant ActionDispatch::XmlParamsParser
/usr/share/redmine/config/application.rb:55:in `<class:Application>'
/usr/share/redmine/config/application.rb:8:in `<module:RedmineApp>'
/usr/share/redmine/config/application.rb:7:in `<top (required)>'
/usr/share/redmine/Rakefile:4:in `require'
/usr/share/redmine/Rakefile:4:in `<top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)

尝试从redmine per this answer 目录失败,出现mysql2 gem 错误。

ubuntu@host:/var/www/html/redmine/plugins/redmine_agile$ cd ../..
ubuntu@host:/var/www/html/redmine$ sudo bundle exec rake redmine:plugins NAME=redmine_agile RAILS_ENV=production
(in /usr/share/redmine)
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/usr/share/redmine/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `eval'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `each'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/usr/share/redmine/config/environment.rb:14:in `<top (required)>'
/usr/share/redmine/lib/tasks/redmine.rake:52:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'

Caused by:
Gem::LoadError: mysql2 is not part of the bundle. Add it to your Gemfile.
/var/lib/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/usr/share/redmine/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `eval'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `each'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/usr/share/redmine/config/environment.rb:14:in `<top (required)>'
/usr/share/redmine/lib/tasks/redmine.rake:52:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => redmine:plugins:migrate => environment
(See full trace by running task with --trace)

【问题讨论】:

    标签: ruby-on-rails redmine redmine-plugins


    【解决方案1】:

    不必要地使用sudoroot 运行命令是解决某些问题的常见原因。

    因此,在几乎所有情况下,您都不应该使用 sudo 来运行您的 rake 任务。相反,使用通常运行应用服务器的用户,例如www-data

    # first change to the user that usually runs your app
    sudo -u www-data /bin/bash -i
    /var/www/html/redmine
    
    # Now run your rake task (without prefixing it with sudo)
    bundle exec rake redmine:plugins NAME=redmine_agile RAILS_ENV=production
    

    【讨论】:

    • 感谢您的回答,很抱歉花了一段时间才回复您。我即将更新我的问题。
    【解决方案2】:

    这个错误分明是说你没有安装Gem 'mysql2' 有没有运行命令bundle install?你可以试试关注吗

    在您的项目根文件夹中,请运行以下命令

    gem list mysql2
    

    它应该向您显示本地 gem,并列出已安装的 mysql2

    如果它没有安装,那意味着你要么无法安装 mysql2,要么没有运行bundle install 命令。也许您可以尝试以下方法

    在您的Gemfile 中添加以下行

    gem "mysql2", "0.3.14"
    

    现在运行以下命令

    bundle install
    

    现在检查mysql2是否真的安装了

    gem list mysql2
    

    如果是,那么一切都很好,希望它有效。

    【讨论】:

    • 感谢您的回答。很抱歉花了这么长时间才回复您。当我运行gem list mysql2 时,我得到mysql2 (0.5.2, 0.4.3)。想法?
    • 好的,我最终运行了sudo gem install redmine_crm,然后运行了sudo bundle install,结果出现了一个新错误。
    • 这意味着您之前的错误已经消失,请接受回复并将新问题与新错误消息的详细信息一起提出。
    • 因为另一个答案的建议是最直接让我取得进步的建议,所以我接受了它作为答案。
    猜你喜欢
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 2012-12-21
    • 2011-08-16
    • 2012-12-20
    • 2011-08-12
    • 2011-12-19
    相关资源
    最近更新 更多