如何安装Ruby和RubyGems

Python018

如何安装Ruby和RubyGems,第1张

Windows

下载并安装Ruby Installer for Windows.安装程序已经包含了RubyGems。

请确保当你安装和使用vmc时候使用带Ruby功能的命令提示符窗口,从Windows的“开始”菜单中的“所有程序”→“Ruby<VERSION>→启动命令提示符使用Ruby"。

最后,从Ruby命令提示符更新RubyGems

[plain] view plain copy print?prompt>gem update --system

Windows Gemfiles支持

一旦你安装了Ruby,你可以按照说明来部署app和使用Gemfile,部署Ruby应用到Cloud Foundry

Windows用户要注意以下几点:

当Windows机器上生成Gemfile.lock文件,它往往包含与Windows匹配特定版本的gems,例如mysql2,thin,PG含有“-X86-mingw32的”的后缀。

例如,在Windows机器上运行包安装用的Gemfile,看起来像这样:

[plain] view plain copy print?

gem 'sinatra'

gem 'mysql2'

gem 'json'

结果是Gemfile.lock看起来如下:

[plain] view plain copy print?GEMremote: http://rubygems.org/specs: json (1.7.3) mysql2 (0.3.11-x86-mingw32) rack (1.4.1) rack-protection (1.2.0)rack sinatra (1.3.2)rack (~>1.3, >= 1.3.6)rack-protection (~>1.2)tilt (~>1.3, >= 1.3.3) tilt (1.3.3)PLATFORMSx86-mingw32DEPENDENCIESjsonmysql2sinatra

Cloud Foundry能够正确地安装这些gems,而不需要修改你的Gemfile.lock

Mac OS X

10.5和更高版本的Mac

OS X已经安装Ruby和RubyGems。

如果您使用的是早期版本的Mac

OS,请下载并安装最新版本的 Ruby 和RubyGems.

Ubuntu

从一个终端,使用apt-get命令行工具来安装Ruby和RubyGems,如下所示

安装完整的Ruby包和RubyGems

[plain] view plain copy print?

prompt$ sudo apt-get install ruby-full rubygems

测试确保路径下有gem命令:

[plain] view plain copy print?

如果命令没有找到,则更新相应的PATH变量,例如,您可以使用以下行:更新.bashrc文件

[plain] view plain copy print?

export PATH=$PATH:/var/lib/gems/1.8/bin

prompt$ which gem

更新RubyGems (Ubuntu 10.04 only):

[plain] view plain copy print?

prompt$ sudo gem install rubygems-update

prompt$ sudo /var/lib/gems/1.8/bin/update_rubygems

RedHat/Fedora

打开终端,使用yum命令行工具来安装Ruby和RubyGems,如下所示

安装Ruby:

[plain] view plain copy print?

prompt$ sudo yum install ruby

如果您使用的是企业Linux RedHat 6,开启可选通道Red Hat Network (RHN).

安装RubyGems:

[plain] view plain copy print?

prompt$ sudo yum install rubygems

Centos

打开终端,使用yum命令行工具来安装Ruby和RubyGems,如下所示

安装基本的包:

[plain] view plain copy print?

prompt$ yum install -y ruby

安装额外的Ruby包和文档:

[plain] view plain copy print?

prompt$ yum install -y ruby-devel ruby-docs ruby-ri ruby-rdoc

安装RubyGems:

[plain] view plain copy print?

prompt$ yum install -y rubygems

SuSE

打开终端,使用yast 命令行工具来安装Ruby和RubyGems,如下所示

安装Ruby:

[plain] view plain copy print?

prompt$ yast -i ruby

安装RubyGems:

[plain] view plain copy print?

prompt$ yast -i rubygems

Debian

You use Ruby Version Manager (rvm) to install Ruby and RubyGems on Debian. The following procedure shows how to install rvm if you have not already done so.

Use the following apt-get command-line tool to install the required packages:

prompt$ sudo apt-get install gcccurl git-core build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev

Run the bash script to install rvm from Ruby Version Manager.

prompt$ bash <<curl -s https://rvm.beginrescueend.com/install/rvm

Edit your ~/.bashrc file as described by the RVM installation in the precding step.

Use rvm to install Ruby and RubyGems as shown:

prompt$ rvm package install zlib

prompt$ rvm install 1.9.2 -C --with-zlib-dir=$rvm_path/usr

prompt$ rvm use 1.9.2

当看到# Thank you for using RVM! 这样的文字时说明rvm 安装完成 

rvm执行前需 source /etc/profile.d/rvm.sh

若提示找不到公钥,执行下边语句,然后重新执行

若提示curl 未找到命令,执行下边语句

查询已经安装的ruby    rvm list                    

列出已知的ruby版本    rvm list known

安装一个ruby版本        rvm install 1.9.3      

卸载一个已安装版本    rvm remove 1.9.2