首页 > 代码库 > Ubuntu 12.04,配置Ruby on Rails开发环境

Ubuntu 12.04,配置Ruby on Rails开发环境

零、Ubuntu的安装

官网下载,我装的是12.04的x64版。

 

一、系统升级

更换ubuntu的源

1.备份更新源

$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

2.修改更新源

$ sudo gedit /etc/apt/sources.list

使用以下网易源或搜狐源,直接替换文件内容(教育网用户请搜索教育网神速专用源)

网易:

deb http://mirrors.163.com/ubuntu/ precise main restricteddeb-src http://mirrors.163.com/ubuntu/ precise main restricteddeb http://mirrors.163.com/ubuntu/ precise-updates main restricteddeb-src http://mirrors.163.com/ubuntu/ precise-updates main restricteddeb http://mirrors.163.com/ubuntu/ precise universedeb-src http://mirrors.163.com/ubuntu/ precise universedeb http://mirrors.163.com/ubuntu/ precise-updates universedeb-src http://mirrors.163.com/ubuntu/ precise-updates universedeb http://mirrors.163.com/ubuntu/ precise multiversedeb-src http://mirrors.163.com/ubuntu/ precise multiversedeb http://mirrors.163.com/ubuntu/ precise-updates multiversedeb-src http://mirrors.163.com/ubuntu/ precise-updates multiversedeb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ precise-security main restricteddeb-src http://mirrors.163.com/ubuntu/ precise-security main restricteddeb http://mirrors.163.com/ubuntu/ precise-security universedeb-src http://mirrors.163.com/ubuntu/ precise-security universedeb http://mirrors.163.com/ubuntu/ precise-security multiversedeb-src http://mirrors.163.com/ubuntu/ precise-security multiversedeb http://extras.ubuntu.com/ubuntu precise maindeb-src http://extras.ubuntu.com/ubuntu precise main

搜狐:

deb http://mirrors.sohu.com/ubuntu/ precise main restricteddeb-src http://mirrors.sohu.com/ubuntu/ precise main restricteddeb http://mirrors.sohu.com/ubuntu/ precise-updates main restricteddeb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricteddeb http://mirrors.sohu.com/ubuntu/ precise universedeb-src http://mirrors.sohu.com/ubuntu/ precise universedeb http://mirrors.sohu.com/ubuntu/ precise-updates universedeb-src http://mirrors.sohu.com/ubuntu/ precise-updates universedeb http://mirrors.sohu.com/ubuntu/ precise multiversedeb-src http://mirrors.sohu.com/ubuntu/ precise multiversedeb http://mirrors.sohu.com/ubuntu/ precise-updates multiversedeb-src http://mirrors.sohu.com/ubuntu/ precise-updates multiversedeb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiversedeb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiversedeb http://mirrors.sohu.com/ubuntu/ precise-security main restricteddeb-src http://mirrors.sohu.com/ubuntu/ precise-security main restricteddeb http://mirrors.sohu.com/ubuntu/ precise-security universedeb-src http://mirrors.sohu.com/ubuntu/ precise-security universedeb http://mirrors.sohu.com/ubuntu/ precise-security multiversedeb-src http://mirrors.sohu.com/ubuntu/ precise-security multiversedeb http://extras.ubuntu.com/ubuntu precise maindeb-src http://extras.ubuntu.com/ubuntu precise main

3.更新

$ sudo apt-get update

以上一步必须正常通过。

安装curl:

$ sudo apt-get install curl

 

二、使用RVM安装Ruby

RVM = Ruby Version Manager

输入以下命令安装RVM,并安装最新stable版的ruby

$ \curl -L https://get.rvm.io | bash -s stable --ruby

安装完成后,输入以下命令检查ruby安装情况:

$ ruby -vruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

若已安装RVM,则使用以下命令:

$ rvm get stable --autolibs=enable$ rvm install ruby$ rvm --default use ruby-2.1.2

 

三、安装JavaScript Runtime

$ sudo apt-get install nodejs

 

四、更新Gem Manager

更新gem:

$ gem update --system$ gem -v2.4.1

更新gem源:

$ gem source -l$ gem source -r https://rubygems.org/$ gem source -a http://ruby.taobao.org/

  

五、更新RVM全局gemset

查看全局gemset中的gem:

$ rvm gemset use global
$ gem list

更新至最新的stable gem:

$ gem update

安装nokogiri:(慢)

$ gem install nokogiri

 

六、安装Rails

建立一个rails4.1的gemset

$ rvm use ruby-2.1.2@rails4.1 --create

安装最新版本的rails

$ gem install rails$ rails -v

例如,你可以再建立一个rails3.2的gemset,安装

$ rvm use ruby-2.1.2@rails3.2 --create$ gem install rails --version=3.2.19$ rails -v

在gemset间切换:

$ rvm use ruby-2.1.2@rails4.1$ rvm use ruby-2.1.2@rails3.2

 

七、rails的hello world

切换至工作目录

$ rails new demo
$ rails s

用浏览器打开http://localhost:3000/,显示如下图片说明安装成功

 

本文参考http://railsapps.github.io/installrubyonrails-ubuntu.html,感谢作者对新人的无私帮助

Ubuntu 12.04,配置Ruby on Rails开发环境