ruby and rails常见问题及错误归纳记录

1.手工下载了Ruby1.9.2源码编译安装后,安装rails事出现了 no such file to load -- zlib 错误

原因:缺少zlib;
解决办法:安装zlib1g 和 zlib1g-dev 包,然后
1)回到ruby源码目录/ext/zlib 下
2)ruby extconf.rb
3)make
4)sudo make install

 

2.使用gem install rails时Error installing rails:     bundler requires RubyGems version >= 1.3.6
原因:gem版本太低,估计也是直接从源里面用apt方式安装的。

解决办法:官网给出的方法 http://rubygems.org/pages/download

一般使用后面这个命令升级即可: gem update --system;
如果rubygems版本为1.1或者1.2,需要先安装用于gems升级的个东东
gem install rubygems-update
update_rubygems            

如果没有安装过rubygems,那就老实下载安装吧。下载完进入目录使用ruby setup.rb即可。

 

3.rake db:create的时候提示以下错误:

rake aborted!
uninitialized constant Rake::DSL
D:/develop/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'

原因:

解决办法:打开RakeFile文件,在require 'rake'上面加入 require  'rake/dsl_definition'  

 

4.执行rake db:migrate的时候报rake aborted!
Mysql::Error: query: not connected: SHOW TABLES
Tasks: TOP => db:migrate

原因:缺少相关的dll文件,导致无法建立MySQL的查询连接;

解决办法:到http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll 下载libmySQL.dll文件拷贝到ruby安装目录下的bin目录下,直接拷贝mysql安装目录下的libmySQL.dll文件我试过是没有效果的。

 

5.执行rails server的时候报错$RUBY_PATH/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite3.
rb:6:in `require': no such file to load -- sqlite3/sqlite3_native (LoadError)

原因:因为使用了sqlite3,而本地缺少sqlite3的本地链接库;

解决办法:去http://www.sqlite.org/download.html 找到对应的sqlite3的本地链接库文件,如windows下载sqlite-dll-win32-x86-3070701.zip文件后解压其中的sqlite3.dll文件放入到$RUBY_PATH/bin目录下即可。

 

6.执行rails  server的时候报错:/var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

 

from /var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'

from /var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'

from /var/lib/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'

原因:没有js运行时环境

解决办法:安装js运行时环境,比如sudo apt-get install nodejs

 

7.安装NOKOGIRI 报错 LIBXSLT IS MISSING

Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... no
-----
libxslt is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

原因:需要ruby 1.8 or 1.9, libxml2, libxml2-dev, libxslt, libxslt-dev

解决办法:sudo apt-get install libxslt-dev libxml2-dev

你可能感兴趣的:(Ruby,Rails,rubygems)