我无法让rails认出我已安装的mysql2 gem。我使用的是rails 3.1和ruby 1.9.2。我被困在这里..
dan@luci:~$ cd snorby/
Using: /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby
dan@luci:~/snorby$ gem list -l | grep mysql2
mysql2 (0.3.11)
dan@luci:~/snorby$ rails c
Loading development environment (Rails 3.1.0)
1.9.2p290 :001 > require 'mysql2'
LoadError: no such file to load -- mysql2
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from (irb):1
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
dan@luci:~/snorby$ echo $GEM_PATH
/home/dan/.rvm/gems/ruby-1.9.2-p290@snorby:/home/dan/.rvm/gems/ruby-1.9.2-p290@global
dan@luci:~/snorby$ ls -l /home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/gems/mysql2-0.3.11/
total 68
drwxr-xr-x 2 dan dan 4096 2012-08-17 14:22 benchmark
-rw-r--r-- 1 dan dan 12460 2012-08-17 14:22 CHANGELOG.md
drwxr-xr-x 2 dan dan 4096 2012-08-17 14:22 examples
drwxr-xr-x 3 dan dan 4096 2012-08-17 14:22 ext
-rw-r--r-- 1 dan dan 25 2012-08-17 14:22 Gemfile
drwxr-xr-x 3 dan dan 4096 2012-08-17 14:22 lib
-rw-r--r-- 1 dan dan 1090 2012-08-17 14:22 MIT-LICENSE
-rw-r--r-- 1 dan dan 1099 2012-08-17 14:22 mysql2.gemspec
-rw-r--r-- 1 dan dan 99 2012-08-17 14:22 Rakefile
-rw-r--r-- 1 dan dan 11978 2012-08-17 14:22 README.md
drwxr-xr-x 4 dan dan 4096 2012-08-17 14:22 spec
drwxr-xr-x 2 dan dan 4096 2012-08-17 14:22 tasks
dan@luci:~/snorby$ rvm info
ruby-1.9.2-p290@snorby:
system:
uname: "Linux luci 2.6.32-37-powerpc #81-Ubuntu Fri Dec 2 21:46:08 UTC 2011 ppc GNU/Linux"
bash: "/bin/bash => GNU bash, version 4.1.5(1)-release (powerpc-unknown-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.10.0 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]"
updated: "7 months 10 days 23 hours 13 minutes 10 seconds ago"
ruby:
interpreter: "ruby"
version: "1.9.2p290"
date: "2011-07-09"
platform: "powerpc-linux"
patchlevel: "2011-07-09 revision 32553"
full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [powerpc-linux]"
homes:
gem: "/home/dan/.rvm/gems/ruby-1.9.2-p290@snorby"
ruby: "/home/dan/.rvm/rubies/ruby-1.9.2-p290"
binaries:
ruby: "/home/dan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
irb: "/home/dan/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
gem: "/home/dan/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
rake: "/home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/bin/rake"
environment:
PATH: "/home/dan/.rvm/gems/ruby-1.9.2-p290@snorby/bin:/home/dan/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/dan/.rvm/rubies/ruby-1.9.2-p290/bin:/home/dan/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
GEM_HOME: "/home/dan/.rvm/gems/ruby-1.9.2-p290@snorby"
GEM_PATH: "/home/dan/.rvm/gems/ruby-1.9.2-p290@snorby:/home/dan/.rvm/gems/ruby-1.9.2-p290@global"
MY_RUBY_HOME: "/home/dan/.rvm/rubies/ruby-1.9.2-p290"
IRBRC: "/home/dan/.rvm/rubies/ruby-1.9.2-p290/.irbrc"
RUBYOPT: ""
gemset: "snorby"
dan@luci:~/snorby$ bundle exec gem list -l | grep mysql2
dan@luci:~/snorby$ echo $?
1
答案 0 :(得分:1)
Rails在启动时会自动使用Bundler.setup
,它与命令行中的bundle exec
等效,允许加载 mysql gem,你需要它Gemfile
并且运行bundle install
,最好是将它放在适当的组中 - 有些项目使用 pg 进行生产,使用 mysql 进行开发,如果您计划始终使用它,那么它可以指定没有组。