---
title: "Rails环境配置"
author: "pluto418"
date: "2013-03-10T14:35:12Z"
tags: []
categories: ["企业架构"]
slug: "rails"
draft: false
lastmod: "2013-08-17T15:52:41Z"
id: 1827079
url: "https://pluto418.iteye.com/blog/1827079"
---

**1. 安装 RubyInstaller**  
http://rubyinstaller.org/downloads/  
建议安装版本1.9.3, 2.0版本有些软件兼容性不太好  
exe文件 直接下一步下一步。安装完ruby -v查看版本

**2. 更改gem source**  
通过gem sources命令配置源，或通过修改Gemfile中的source语句可以实现

常用的source，比官方的速度快  
http://rubygems.org/  
http://gems.github.com  
http://gems.rubyforge.org  
http://ruby.taobao.com  
http://mirrors.tuna.tsinghua.edu.cn/rubygems/

显示当前使用的sources  gem sources  
添加一个source              gem sources -a url地址  
删除一个source              gem sources -r url地址  
更新source cache          gem sources -u

**3. 安装Development Kit**  
http://rubyinstaller.org/downloads/

解压  
   ruby dk.rb init  
   ruby dk.rb install

**4. Rails安装**  
cmd 窗口执行，如果通过代理 先执行 set http\_proxy=http://username:password@192.168.xx.xx:8080  
https\_proxy=http://username:password@192.168.xx.xx:8080  
经常使用可以在环境变量里面增加 http\_proxy，https\_proxy

gem install rails  
安装完rails -v查看版本  
gem install json sass  
gem install mysql mysql2  
OR  
gem install mysql2 — ‘–with-mysql-dir=”C:\\MySQL\\MySQL Server 5.5″‘

 

gem uninstall sqlite

gem list --remote --all sqlite  
gem list --all sqlite

**5. 安装MySQL5.5**  
MySQL安装目录lib/目录 libmysql.dll 替换到 ruby安装目录/bin

**6. 项目相关操作**  
rails new testProject -d=mysql  
cd testProject  
rails server  
rails generate controller welcome index  
rails destory controller welcome index  
rails generate model users username:string sex:boolean favor:text  
rails destory model users  
rails generate scaffold users username:string sex:boolean favor:text  
rails destory scaffold users

rake db:migrate  
rake db:rollback  
rake db:rollback STEP=3  
rake db:migrate:up VERSION=20120104120000

修改 bundle install URL  
Gemfile 第一行 source ‘http://ruby.taobo.org’

访问 http://127.0.0.1:3000

具体实例可参考http://rubyer.me/blog/231/单表操作的例子。  
使用RubyMine可以参考 http://blog.163.com/rui\_haha/blog/static/197757119201110295216618/