use rvm install and manage ruby version

rvm 全称Ruby Version Manager,  确实是一个非常好用的ruby版本管理以及安装工具.
下面介绍一下rvm的安装, 使用rvm, 安装ruby, 以及gem的使用.

一、安装rvm

官方网站上介绍得很简单, 但是使用官方网站安装会出现问题, SSL的问题. 所以我分两步进行, 第一步下载安装脚本. 第二步修改安装脚本. 第三步安装.

以下介绍的是使用root用户在CentOS中安装rvm的过程.

1. 下载脚本到ins文件中. 注意使用了curl的-k选项, 因为地址是https的. 不加-k会报异常.

[root@db-172-16-3-33 ~]# curl -k https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer >./ins

2. 修改ins脚本中的curl都加上-k否则会无法使用.

vi ins
需要修改两处curl.
curl -sk https://api.github.com/repos/wayneeseguin/rvm/tags
if curl -kL ${_url} -o ${rvm_archives_path}/${_file}

3. 使用修改后的ins脚本安装rvm

[root@db-172-16-3-33 ~]# cat ins|bash -s stable
输出结果 :
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1023k  100 1023k    0     0   173k      0  0:00:05  0:00:05 --:--:--  383k

Installing RVM to /usr/local/rvm/
    Creating RVM system user group 'rvm'

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask g+w`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# root,
#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne

4. 修改root 下的环境变量

vi ~/.bash_profile
export PATH=/usr/local/rvm/bin:/opt/git1.7.10.2/bin:$PATH
更新环境变量.
. ~/.bash_profile
这里就安装完rvm了

二、rvm的使用, 简单的介绍一下

[root@db5 ~]# rvm list help

  Usage:

    rvm list [action]

  Actions:

  {help,known,gemsets,default [string],rubies,strings,known_strings,ruby_svn_tags}

1. 列出rvm管理的软件及版本

[root@db5 ~]# rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p358]
[ruby-]1.8.7-head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2-p180
[ruby-]1.9.2-p290
[ruby-]1.9.2-p318
[ruby-]1.9.2[-p320]
[ruby-]1.9.2-head
[ruby-]1.9.3-preview1
[ruby-]1.9.3-rc1
[ruby-]1.9.3-p0
[ruby-]1.9.3-p125
[ruby-]1.9.3-[p194]
[ruby-]1.9.3-head
ruby-head

# GoRuby
goruby

# TheCodeShop - MRI experimental patches
tcs

# JRuby
jruby-1.2.0
jruby-1.3.1
jruby-1.4.0
jruby-1.6.5
jruby-1.6.5.1
jruby-1.6.6
jruby-1.6.7
jruby[-1.6.7.2]
jruby-head
jruby-1.7.0.preview1

# Rubinius
rbx-1.0.1
rbx-1.1.1
rbx-1.2.3
rbx-1.2.4
rbx[-head]
rbx-2.0.testing

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Kiji
kiji

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby[-0.10]
macruby-nightly
macruby-head

# IronRuby -- Not implemented yet.
ironruby-0.9.3
ironruby-1.0-rc2
ironruby-head

三、使用RVM安装ruby

从上面的输出我们能看到rvm管理的ruby版本中包含了当前的稳定版1.9.3-p194, 接下来就安装这个版本.

但是注意, 使用rvm安装的话需要联网, 怎么办呢? 可以不联网吗? 可能不可以, 因为要获得依赖关系什么的, 但是可以提前下载好安装包房到archives目录下, 这样可以省去下载包的过程.

1. 联网安装

[root@db5 ~]# rvm install ruby-1.9.3-p194
输出
Fetching yaml-0.1.4.tar.gz to /usr/local/rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  460k  100  460k    0     0  91728      0  0:00:05  0:00:05 --:--:--  190k
Extracting yaml-0.1.4.tar.gz to /usr/local/rvm/src
Prepare yaml in /usr/local/rvm/src/yaml-0.1.4.
Configuring yaml in /usr/local/rvm/src/yaml-0.1.4.
Compiling yaml in /usr/local/rvm/src/yaml-0.1.4.
Installing yaml to /usr/local/rvm/usr
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-1.9.3-p194, this may take a while depending on your cpu(s)...

ruby-1.9.3-p194 - #fetching
ruby-1.9.3-p194 - #downloading ruby-1.9.3-p194, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
.... 略
到安装rubygems的时候会出错, 无法获取版本号. 所以需要手工安装rubygems.
-- 下载rubygems错误,貌似版本信息没有获取到.
Retrieving rubygems-
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404
The requested url does not exist: 'http://production.cf.rubygems.org/rubygems/rubygems-.tgz'
Trying ftp:// URL instead.
CTRL+C退出
-- 手动安装rubygems, 见第3步

2. 下载好包后放到archives目录下再安装

如果下载太慢, 也可以先下载好yaml-0.1.4.tar.gz, ruby-1.9.3-p194.tar.bz2 放在/usr/local/rvm/archives下面

然后执行

rvm install ruby-1.9.3-p194

3. 安装rubygems

下载rubygems安装包.

wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz

解压

tar -zxvf rubygems-1.8.24.tgz

放到一个目录, (可选)

mv rubygems-1.8.24 /usr/local/rvm/src/
cd /usr/local/rvm/src/rubygems-1.8.24
-- 由于是rvm管理的ruby环境, 所以在安装rubygems前, 先转到对应的ruby 环境, --default表示设置为默认的ruby环境
[root@db-172-16-3-33 rubygems-1.8.24]# rvm use ruby-1.9.3-p194 --default
Using /usr/local/rvm/gems/ruby-1.9.3-p194
干了什么呢? 弄了个软链接.
[root@db5 rubies]# pwd
/usr/local/rvm/rubies
[root@db5 rubies]# ll
total 4.0K
lrwxrwxrwx 1 root rvm   37 May 25 10:47 default -> /usr/local/rvm/rubies/ruby-1.9.3-p194
drwxr-xr-x 6 root rvm 4.0K May 25 11:34 ruby-1.9.3-p194
-- 安装rubygems
[root@db-172-16-3-33 rubygems-1.8.24]# ruby setup.rb
输出结果
RubyGems 1.8.24 installed

== 1.8.24 / 2012-04-27

* 1 bug fix:

  * Install the .pem files properly. Fixes #320
  * Remove OpenSSL dependency from the http code path

------------------------------------------------------------------------------

RubyGems installed the following executables:
        /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/gem

4. 列出当前rvm管理的软件

[root@db5 ruby-1.9.3-p194]# rvm list

rvm rubies

=* /usr/local/rvm/scripts/list: line 294: /usr/local/rvm/rubies/ruby-1.9.3-p194/config: No such file or directory
ruby-1.9.3-p194 [  ]

# => - current
# =* - current && default
#  * - default

5. 重新安装

rvm reinstall ruby-1.9.3-p194

6. 移除已安装的软件

rvm remove ruby-1.9.3-p194

四、gem的使用介绍

1.  源管理,添加淘宝源

[root@db5 soft_bak]# gem source --add 'http://ruby.taobao.org/'
http://ruby.taobao.org/ added to sources
[root@db5 soft_bak]# gem source -l
*** CURRENT SOURCES ***

http://rubygems.org/
http://ruby.taobao.org/

2. 更新源cache

[root@db5 soft_bak]# gem source -u
source cache successfully updated

3. 查看源里有哪些软件

gem query -r -a
-- 也可使用规则表达式
[root@db5 soft_bak]# gem query -r -n 'redis'

*** REMOTE GEMS ***

active-redis (0.1.0 ruby)
adapter-redis (0.5.1 ruby)
bayes_on_redis (0.2.2 ruby)
bayes_on_redis_internal (0.0.1 ruby)
cache-machine-redis (0.0.1 ruby)
cs-em-hiredis (0.1.2 ruby)
datalogger-redis (0.0.2 ruby)
datastore_redis (0.0.8 ruby)
dm-redis-adapter (0.6.2 ruby)
dsander-redis (1.0.6 ruby)
dsander-redis-store (0.3.8 ruby)
easyredis (0.0.6 ruby)
em-hiredis (0.1.1 ruby)
em-redis (0.3.0 ruby)
em-redislite (0.2.2 ruby)
eventmachine-redis (0.1.3 ruby)
extraloop-redis-storage (0.0.12 ruby)
eycloud-recipe-redis (0.2.0 ruby)
fakeredis (0.3.1 ruby)
faye-redis (0.1.0 ruby)
feedzirra-redis (0.1.1 ruby)
fluent-plugin-redis (0.2.0 ruby)
goncalossilva_redis-session-store (0.1.8.1 ruby)
guard-redis (0.1.0 ruby)
hiera-redis (0.1.3 ruby)
hiera-redis-backend (0.0.1 ruby)
hiredis (0.4.5 ruby java java)
honkster-redis-store (0.3.16 ruby)
i18n_redis (0.0.2 ruby)
integration_test_redis (0.0.2 ruby)
jashmenn-redis-lock (0.1.1 ruby)
joffice_redis (0.1.1 ruby)
kali-redis (0.1.1 ruby)
mlanett-redis-lock (0.1.1 ruby)
mock_redis (0.4.1 ruby)
namespaced_redis (1.0.2 ruby)
newrelic-redis (1.3.2 ruby)
nono-redis-store (1.0.0 ruby)
opengotham_redis-namespace (0.4.4 ruby)
openid-redis-store (0.0.2 ruby)
orm-redis (0.0.0 ruby)
qu-redis (0.1.4 ruby)
rack-session-redis (0.0.3 ruby)
rails3-redis-session-store (0.3.0 ruby)
rails_redis_cache (0.2.0 ruby)
redis (3.0.0 ruby)
redis-actionpack (3.2.3 ruby)
redis-activesupport (3.2.3 ruby)
redis-aid (0.1.0 ruby)
redis-cache (1.0.1 ruby)
redis-classy (1.0.2 ruby)
redis-column (0.0.3 ruby)
redis-connection-ssl (0.0.1 ruby)
redis-connection-universal (0.0.1 ruby)
redis-diff_match_patch (1.1.1 ruby)
redis-dump (0.3.2 ruby)
redis-expiring-set (0.1.2 ruby)
redis-expiring_counter (1.0.0.0 ruby)
redis-friendships (0.2 ruby)
redis-health (0.0.1 ruby)
redis-i18n (0.6.0 ruby)
redis-load (0.2 ruby)
redis-lock (0.1.0 ruby)
redis-messages (0.1 ruby)
redis-mmm (0.1.1 ruby)
redis-model (0.1.3 ruby)
redis-model-extension (0.3.3 ruby)
redis-mutex (1.2.3 ruby)
redis-namespace (1.1.0 ruby)
redis-native_hash (0.2.1 ruby)
redis-objective (0.1.0 ruby)
redis-objects (0.5.2 ruby)
redis-orm (0.0.4 ruby)
redis-persistence (0.0.7 ruby)
redis-rack (1.4.1 ruby)
redis-rack-cache (1.2 ruby)
redis-rails (3.2.3 ruby)
redis-repeater (0.2.6 ruby)
redis-retry (0.1.0 ruby)
redis-roc (0.5.3 ruby)
redis-scheduler (0.4 ruby)
redis-scripted (0.0.3 ruby)
redis-search (0.8.0 ruby)
redis-semaphore (0.1.1 ruby)
redis-server (0.0.5 ruby)
redis-session-store (0.1.9 ruby)
redis-settings (0.2.1 ruby)
redis-sinatra (1.3.2 ruby)
redis-slave (0.0.3 ruby)
redis-spawn (0.0.5 ruby)
redis-store (1.1.0 ruby)
redis-structured-multi (0.0.2 ruby)
redis-textsearch (0.2.0 ruby)
redis-timeline (0.1.6 ruby)
redis-types (0.1.7 ruby)
redis-ui (0.1.3 ruby)
redis2-session-store (0.0.3 ruby)
redis_autocomplete (0.1.4 ruby)
redis_buddy (1.0.0 ruby)
redis_cache (0.0.1 ruby)
redis_cache_mailer_delivery (0.0.6 ruby)
redis_directory (1.0.4 ruby)
redis_failover (0.8.3 ruby)
redis_feature_control (0.0.2 ruby)
redis_feed (0.0.1 ruby)
redis_geo (0.0.0 ruby)
redis_knock (0.0.2 ruby)
redis_logger (0.1.0 ruby)
redis_master_slave (0.0.1 ruby)
redis_on_heroku (0.0.1 ruby)
redis_orm (0.6.2 ruby)
redis_props (0.3 ruby)
redis_record (0.0.1 ruby)
redis_resque_initializer (0.0.1 ruby)
redis_ring (0.1.3 ruby)
redis_ring_client (0.1.2 ruby)
redis_selector (0.1.0 ruby)
redis_session_store (0.0.2 ruby)
redis_snippets (0.0.5 ruby)
redis_status (0.1.1 ruby)
redis_storage (0.4.0 ruby)
redis_store_jr (0.2.1 ruby)
redis_support (0.0.18 ruby)
redis_throttle (0.1.0 ruby)
redis_voteable (0.1.2 ruby)
redis_wrapper (0.2.0 ruby)
redis_wrapper_rails (0.2.0 ruby)
redisarray (0.0.1 ruby)
rediscover (0.0.2 ruby)
redisearch (0.1.0 ruby)
redised (0.2.0 ruby)
redish (0.0.1 ruby)
redisk (0.2.2 ruby)
redislog (1.0.0 ruby)
redismapper (0.0.1 ruby)
redismodel (0.1.8 ruby)
redismq (0.0.6 ruby)
redisque (1.0.1 ruby)
redisrecord (0.1 ruby)
redisrpc (0.3.5 ruby)
redistat (0.5.0 ruby)
redisted (0.0.2 ruby)
redistry (0.1.3 ruby)
rspec-redis_helper (0.1.2 ruby)
ruby-redis (0.0.2 ruby)
ruby-redis-portertech (0.0.3 ruby)
ruby_redis_lock (0.1.0 ruby)
ruote-redis (2.2.0 ruby)
ryansch-mock_redis (0.3.0 ruby)
simple-redis-server (0.0.1 ruby)
simple_redis_cache (0.0.2 ruby)
simredis (0.0.5 ruby)
sinatra-redis (0.3.0 ruby)
sinatra-redis-auth (0.1.1 ruby)
sprockets-cache-redis (0.0.3 ruby)
superfeedr-em-redis (0.3.7 ruby)
synapse_redis_logger (0.1.0 ruby)
tavern-redis (0.0.2 ruby)
unified-redis (0.0.2 ruby)
uri-redis (0.4.2 ruby)
xlymian-redis-store (0.3.8 ruby)
yam-redis-with-retries (2.2.2.1 ruby)

4. 其他gem命令

[root@db5 ~]# gem help commands
GEM commands are:

    build             Build a gem from a gemspec
    cert              Manage RubyGems certificates and signing settings
    check             Check installed gems
    cleanup           Clean up old versions of installed gems in the local
                      repository
    contents          Display the contents of the installed gems
    dependency        Show the dependencies of an installed gem
    environment       Display information about the RubyGems environment
    fetch             Download a gem and place it in the current directory
    generate_index    Generates the index files for a gem server directory
    help              Provide help on the 'gem' command
    install           Install a gem into the local repository
    list              Display gems whose name starts with STRING
    lock              Generate a lockdown list of gems
    outdated          Display all gems that need updates
    owner             Manage gem owners on RubyGems.org.
    pristine          Restores installed gems to pristine condition from files
                      located in the gem cache
    push              Push a gem up to RubyGems.org
    query             Query gem information in local or remote repositories
    rdoc              Generates RDoc for pre-installed gems
    search            Display all gems whose name contains STRING
    server            Documentation and gem repository HTTP server
    sources           Manage the sources and cache file RubyGems uses to search
                      for gems
    specification     Display gem specification (in yaml)
    stale             List gems along with access times
    uninstall         Uninstall gems from the local repository
    unpack            Unpack an installed gem to the current directory
    update            Update the named gems (or all installed gems) in the local
                      repository
    which             Find the location of a library file you can require

For help on a particular command, use 'gem help COMMAND'.

Commands may be abbreviated, so long as they are unambiguous.
e.g. 'gem i rake' is short for 'gem install rake'.

【参考】

http://rubygems.org

https://rvm.io

时间: 2024-10-31 20:36:43

use rvm install and manage ruby version的相关文章

了解Ruby Version Manager如何完成更多的工作

尽管 Internet Relay Chat.论坛和http://www.aliyun.com/zixun/aggregation/9591.html">版本控制工具(如 Git 和 Github)令分布式开发变得十分简单,但是重建另一个开发人员的环境将会十分困难.在一个新的开发机器上支持现有代码体,需要至少匹配初始编码人员的部分(也有可能是全部)堆栈,或是匹配增强应用程序所必需的软件组件.堆栈可能要求使用某种操作系统(比如 UNIX®.Linux®.Mac OS 或 Windows®):

redis list operator tested with ruby

redis是一个性能比较出色的内存数据库或者说NOSQL. 下面使用ruby测试一下lpush和lpop的性能. 测试机 : HP DL360G5 16G内存 2颗 4核心Intel(R) Xeon(R) CPU E5405 @ 2.00GHz ruby版本1.9.3-p194 redis版本2.4.14 操作系统 : CentOS 5.2 x64 1. 安装redis-rb (rubygems里面叫redis, github里面叫redis-rb注意) ruby和git安装可以参考前面几篇BL

打造你的OSX开发环境

以下App Store上的软件,你值得拥有. Pages, Numbers, Keynote OS X 三件套. Alfred 和 Spotlight 类似,可以快速启动应用程序和打开文件,但是比 Spotlight 体验好很多. 最好直接去 官网 下载 Alfred 2,并且购买 Powerpack,这样才能发挥 Alfred Workflow 的功能,如果不想花钱,最近有一个 Flashlight 也不错,大有赶超 Alfred 之势. OmniGraffle 比较实用的画图工具,和 Vis

Redis Cluster 实践

一:关于redis cluster 1:redis cluster的现状 reids-cluster计划在redis3.0中推出,可以看作者antirez的声明:http://antirez.com/news/49 (ps:跳票了好久,今年貌似加快速度了),目前的最新版本见:https://raw.githubusercontent.com/antirez/redis/3.0/00-RELEASENOTES 作者的目标:Redis Cluster will support up to ~1000

ruby on rails在fedora18上install

ruby on rails 在fedora18下的安装 天朝的网络原因,安装不是很顺畅,所以把过程记录下备用 前面下载rubygem什么的都比较快,新建一个project的时候会出问题 gem new my_project  会在bundle_install处卡很久,然后提示说某某东西没装,让装一下.. 大体上参考了两篇文章:   [第一篇帖子,google快照里找到的]在Fedora系统安装Ruby on Rails这几年一直在用AS3.0做开发,已经很久没有接触Linux了.博客上挂着Fed

ubuntu下rvm安装ruby报错

问题描述 ubuntu下rvm安装ruby报错 错误如下,在线等,谢谢 rvm install ruby-2.2 Searching for binary rubies, this might take some time. No binary rubies available for: ubuntu/14.04/x86_64/ruby-2.2.1. Continuing with compilation. Please read 'rvm help mount' to get more inf

Ruby版本管理工具RVM的安装和使用教程_ruby专题

RVM 是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换. https://rvm.io/ 如果你打算学习 Ruby / Rails, RVM 是必不可少的工具之一. 这里所有的命令都是再用户权限下操作的,任何命令最好都不要用 sudo.RVM 安装 $ curl -L get.rvm.io | bash -s stable $ source ~/.bashrc $ source ~/.bash_profile 修改 RVM 的 Ruby 安装源到国内的 淘宝镜像服务器,这

怎样在Ubuntu系统下配置Ruby On Rails开发环境

在Linux下使用Ruby On Rails能够对web应用程序的维护和开发变得更加便利,让开发人员能更加专注于系统的逻辑结构,在使用前需先配置Ruby On Rails的开发环境,下面小编就给大家介绍下Ubuntu 12.04如何配置Ruby On Rails开发环境. Ubuntu 12.04 + Ruby 2.0 + Rails 3.2.13 1.安装系统需要的包 $ sudo apt-get install -y build-essential openssl curl libcurl3

《R和Ruby数据分析之旅》—第1章 1.1节Ruby

第1章 握住探险之鞭--认识Ruby R和Ruby数据分析之旅 <夺宝奇兵>一直是我最喜欢的系列电影.在我年少时,哈里森·福特就是我心中的英雄.我一直很喜欢印第安纳·琼斯抽鞭子的样子.其实正是在<夺宝奇兵>里,我第一次知道鞭子是什么东西. <夺宝奇兵>最早的两部--<法柜奇兵>和<魔域奇兵>中,印第安纳正值壮年,坚定刚毅,脾气暴躁.在我看过这两部之后,心里就对他标志性的帽子和鞭子产生了疑惑--为什么一定要戴那样一顶毡帽,为什么居然要拿一条鞭子?