简体   繁体   中英

Rails `require': cannot load such file — mysql2/mysql2 (LoadError) when trying to run an app locally

I'm trying to start my server for an existing rails project on my local machine and i'm getting the error below. Can anyone explain why i'm getting this error and how to fix it?

    $ rails s
    /Users/tomcaflisch/Sites/mysite/refinerycms/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
        from /Users/tomcaflisch/Sites/mysite/refinerycms/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `<top (required)>'
        from /Users/tomcaflisch/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require'
    ...

Here's some posssibly relevant output to help figure out the issue:

$ which ruby
/Users/tomcaflisch/.rvm/rubies/ruby-1.9.3-p0/bin/ruby

$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]

It could be a different of things, but something secure is that your rails application cannot find the mysql gem.

The first advise would be to use ruby 1.9.3 instead of ruby 1.9.1

But the quickest solution should be to install all your gems again for the project.

So go to your website, and delete all the files under /Users/tomcaflisch/Sites/mysite/refinerycms/ruby/ (that will delete the bundle Gems), delete Gemfile.lock , and run: bundle install

That should fix the issue ;)

Before doing that, you can also try to just run bundle update and that may also fix the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM