Windows环境下开发Ruby

来源:互联网 发布:支付宝显示网络不给力 编辑:程序博客网 时间:2024/05/16 09:45

  由于实验需要,需要使用Ruby编写的一个程序,今天从网上收集资料,总结一下

1、下载和安装Ruby

  首先,有两种安装方式,第一种是安装Rails Installer(Windows),第二种是安装源码(这个很麻烦)

  Ruby的官方地址:http://rubyinstaller.org/

                https://www.ruby-lang.org/zh_cn/downloads/

Ruby Installer的下载地址:http://download.csdn.net/detail/jiangzuo/5068755,这个版本是rubyinstaller-1.9.3-p385

  下载完成后解压,安装


  安装结束后,运行ruby -v 显示版本号。如果正常显示Ruby版本号,表示安装成功。


  如果没有显示版本号,则需要添加环境变量

     

             SET RUBY_HOME=C:/ruby             SET PATH=%PATH%;%RUBY_HOME%/bin             SET RUBYOPT=rubygems

2、下载和安装RubyGems

  在第1步安装Rubyinstaller-1.9.3-p385后RubyGems以及自动安装,可以跳过此步骤

  官方网址: http://rubyforge.org(已被墙)

  安装完成后,运行gem -v显示版本号如果正常显示RubyGems版本号,表示安装成功。


3、安装Rails

  官方网址:http://rubyonrails.org/

  Rails推荐在有网络的情况下,远程安装,在命令行执行如下命令:gem install rails --include-dependencies检查状态,在Windows下安装时会碰到这样的错误

      Please update your PATH to include build tools or download the DevKit from            'http://rubyinstaller.org/downloads' and follow the instructions at            'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

这是因为没有安装DevKit的缘故,这时候需要下载Devkit包, DevKit官方网址 http://rubyinstaller.org/downloads/,下载完成后执行这个文件,会解压到这个一个目录。进入这个目录,这个目录就是 <DEVKIT_INSTALL_DIR>。

然后在命令行输入cd <DEVKIT_INSTALL_DIR>进入解压后的目录
输入ruby dk.rb init 
#生成config.yml,这里会检查将要添加DevKit支持的Ruby列表,只支持通过RubyInstaller安装的Ruby 
#如果这里列出的Ruby与你的要求不符,可以手动修改 
输入ruby dk.rb review  
#检查要添加DevKit支持的Ruby列表是否有误,可以略过 

输入ruby dk.rb install 显示消息为:
[INFO] Updating convenience notice gem override for 'C:/Ruby193' 
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'


输入gem install rdiscount --platform=ruby,这一步只是验证DevKit是否安装成功,如果能安装rdiscount成功说明安装DevKit成功,也可以忽略。显示消息
Fetching: rdiscount-1.6.8.gem (100%) Temporarily enhancing PATH to include DevKit... Building native extensions.  This could take a while... Successfully installed rdiscount-1.6.8 1 gem installed Installing ri documentation for rdiscount-1.6.8... Installing RDoc documentation for rdiscount-1.6.8...
如果能安装成功,就说明安装成功。

现在继续Rails的安装,在命令行执行gem install rails --include-dependencies,接着会加载,结束后完成Ruby环境安装。


4、创建Web应用

在命令行输入rails new testweb,会出现以下结果:

在testweb目录下运行rails server,会得到以下结果:


浏览器中输入http://localhost:3000/,如果看到以下页面,说明OK。


    

0 0
原创粉丝点击