Rails会产生错误

时间:2016-01-06 04:18:49

标签: ruby-on-rails rails-generate

每次输入rails generate时都会出现此错误:

/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in
`require':
dlopen(/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle,
9): Library not loaded: libmysqlclient.18.dylib   Referenced from:
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
Reason: image not found -
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
(LoadError)   from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in
`<top (required)>'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in
`require'     from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in
`block (2 levels) in require'     from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in
`each'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in
`block in require'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in
`each'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in
`require'     from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler.rb:99:in
`require'     from
/Users/hadifarhat/simple_cms/config/application.rb:7:in `<top
(required)>'  from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:82:in
`require'     from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:82:in
`preload'     from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:143:in
`serve'   from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:131:in
`block in run'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:125:in
`loop'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:125:in
`run'     from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application/boot.rb:18:in
`<top (required)>'    from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'  from
/Users/hadifarhat/.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'  from -e:1:in `<main>'

2 个答案:

答案 0 :(得分:0)

插入您的GemFile

gem 'mysql2', '~> 0.3.18'

安装一些mysql2依赖

sudo apt-get install libmysql-ruby libmysqlclient-dev

然后捆绑安装

bundle install

答案 1 :(得分:0)

添加到您的GemFile

gem 'mysql2' #For latest version 

然后更新你的包

bundle install 

然后生成rails到ruby文件夹

gem install rails

最后创建项目

rails new project #Project your project name 

希望能帮到你