日期:2014-05-16  浏览次数:20635 次

linux下安装ruby的环境 nginx+passenger出现的问题及解决
今天,帮一个朋友解决gem问题,服务器是 Ubuntu 8.04 Hardy。所有 gem 操作都出 301 错误,gem env 显示如下:

# gem env
RubyGems Environment:
  - VERSION: 0.9.4 (0.9.4)
  - INSTALLATION DIRECTORY: /var/lib/gems/1.8
  - GEM PATH:
     - /var/lib/gems/1.8
  - REMOTE SOURCES:
     - http://gems.rubyforge.org

gem -v 显示版本号是 0.0.4,版本太老了。肯定是 gems.rubyforge.org重定向的原因,用 curl 检查,果然是重定向到 rubygems.org 了。

curl -I gems.rubyforge.org
HTTP/1.1 301 Moved Permanently
Date: Sun, 01 Aug 2010 07:56:15 GMT
Server: Apache/2.2.3 (Red Hat) mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 Phusion_Passenger/2.2.15
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
X-Runtime: 0.000490
Set-Cookie: _test_session=BAh7BiIPc2Vzc2lvbl9pZCIlODdkYjBhYWU5NDg2YjA2MzM5Y2NhOWFjY2VlOGEwYjc%3D--bd78425fafbfa5e8edfb28f87805d82554e5d0b6; path=/; HttpOnly
Location: http://rubygems.org/
Status: 301
Content-Type: httpd/unix-directory

ERROR:  While executing gem ... (Gem::RemoteSourceException)
    HTTP Response 301
<code>

使用 gem sources -r  及 gem sources -c 都不好用,还是出错。最后,删掉重装:

<code>

apt-get remove rubygems
wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
tar xvzf rubygems-1.3.7.tag
cd rubygems-1.3.7
ruby setup.rb

最后提示安装了 /usr/bin/gem1.8,需要做个符号链接:

cd /usr/bin
ln -sf gem1.8 gem

Done.

3.提示以下错误extconf.rb:2:in `require': no such file to load -- mkmf (LoadError) from extconf.rb:2

Building native extensions.? This could take a while...
ERROR:? Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
extconf.rb:2:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:2

原因:缺少mkmf,mkmf.rb is part of the ruby1.8-dev package。

解决办法:sudo apt-get install ruby1.8-dev