[Linux] redhat6安装ruby和gem详解

还是先更改redhat自带的yum、升级python顺带一起

  • Redhat6.5 配置国内的yum源
  • Redhat6.5 升级python2.6到python2.7
  • 安装ruby和rubygem

本文配置:redhat6.5 en

 

一、redhat配置国内163的yum源

1.下载yum 。请从 http://mirrors.163.com/centos/6/os/x86_64/Packages/ 下载,根据自己的版本需要

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-73.el6.centos.noarch.rpm 
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm   
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm 

 

2.卸载redhat自带yum

rpm -qa | grep yum | xargs rpm -e --nodeps

 

3.安装下载的yum包

rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm   
rpm -ivh yum-3.2.29-73.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm 

如果报错:“error: Failed dependencies:
python-urlgrabber >= 3.9.1-10 is needed by yum-3.2.29-73.el6.centos.noarch”,则:
rpm -qa|grep python-urlgrabber得到python-urlgrabber-3.9.1-9.el6.noarch
rpm -e python-urlgrabber-3.9.1-9.el6.noarch然后再安装新版本的python-urlgrabber

 

4.下载163的yum源:
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
备份自带repo以及替换

cp /etc/yum.repos.d/rhel-source.repo /etc/yum.repos.d/rhel-source.repo_bak_1
mv CentOS6-Base-163.repo /etc/yum.repos.d/rhel-source.repo

 

 

二、Redhat6.5 升级python2.6到python2.7,以及yum问题

1.下载和安装python

tar xvf Python-2.7.2.tar.bz2
./configure --prefix=/usr/local/python27 --with-zlib
make
make install
mv /usr/bin/python /usr/bin/python_2.6
ln -s /usr/local/python27/bin/python /usr/bin/

PS:记得加上–with-zlib,因为安装setuptools需要

 

2.配置yum

如果yum不可用,则vi /usr/bin/yum
首行更改为
#!/usr/bin/python2.6

 

 

三、安装ruby和rubygem
1.下载ruby http://www.ruby-lang.org/en/downloads/,我下载的是ruby-2.4.0.tar.gz,安装在/usr/local (所有机器,root)

$ tar -xvzf ruby-2.4.0.tar.gz
$ cd ruby-2.4.0

 

2.配置和编译、安装(所有机器,root)

$ ./configure
$ make
$ make install

 

3.验证(应用用户即可)

$ ruby -v
可考虑配置环境变量: vi /etc/profile
export RUBY_HOME=/usr/local/ruby2.4.0
export PAHT:RUBY_HOME/bin

 

4.安装rubygem

tar xzvf rubygems-1.8.5.tgz
cd rubygems-1.8.5/
ruby setup.rb
gem --version

 

 

报错和问题解决:
1.使用gem遇到报错zlib报错,需要加入zlib,解决方法:
到/usr/local/ruby-2.4.0/ext/zlib 目录下 去扩展zlib

ruby extconf.rb
make
make install

!注意,这里可能是2.4.0有个bug,如果make的时候报错:make: *** No rule to make target `/include/ruby.h’, needed by `zlib.o’. Stop. 请按照如下方式处理: vi MakeFile

2.使用gem遇到openssl报错
gem install redis
ERROR: While executing gem … (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
解决方法:

gem source -r https://rubygems.org/
gem sources -a http://gems.ruby-china.org/
gem sources -u
gem install redis

 

 

 

分类上一篇:     分类下一篇:

Leave a Reply