问题
I installed mysql2 gem using command: gem install mysql2
Done installing documentation for mysql2 after 0 seconds
1 gem installed
But when I do require 'mysql2'
, I get:
LoadError: cannot load such file -- mysql2/mysql2
Even though the gem installed successfully, gem list mysql2
*** LOCAL GEMS ***
mysql2 (0.4.0)
I am using MacOSX with ruby 2.1.5p273
Any suggestions as to where should I be looking ?
回答1:
Are you sure you have quoted gem name like this require 'mysql2'
? Please, show your script.
UPDATE: Looks like a bug in mysql2-0.4.0
version.
If you don't need exactly this version (I doubt so), just rollback to previous latest stable release in 0.3.x
branch:
ruby-2.1.5 in ~/projects › gem install mysql2 -v '~> 0.3.0'
Fetching: mysql2-0.3.20.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.20
1 gem installed
ruby-2.1.5 in ~/projects › irb
>> require 'mysql2'
=> true
>>
回答2:
Try using platform -
gem install mysql2 --platform=ruby
来源:https://stackoverflow.com/questions/32534879/mysql2-0-4-0-ruby-gem-require-error