CentOS配置ruby on rails开发环境

左手 posted @ 2013年12月09日 20:25 in Linux with tags rails PostgreSQL nodejs rails development environment rails环境配置 centos配置rails , 2888 阅读

最近用rails做了一个项目,分享一下开发环境搭建方面的信息。

一、基本信息

  1. 操作系统:CentOS 6.x
  2. 数据库:PostgreSQL 9.x
  3. Ruby版本:2.x
  4. Rails版本:4.x

二、基本软件

1. nodejs
rails中解析js的部份库会用到js引擎,nodejs较为高效,所以配置nodejs。
1). 下载nodejs Linux二进制包,nodejs的安装包可以在这里找到 http://www.nodejs.org/download/
wget http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-x86.tar.gz

2). 解压到/usr/local目录
tar -xzf node-v0.10.22-linux-x86.tar.gz -C /usr/local/

3). 建立软链接方便后期版本替换
ln -s node-v0.10.22-linux-x86 node

4). 添加环境变量
vim /etc/profile
# 在unset -f pathmunge之前加入如下两行,因为要用到pathmunge,所以要加在unset之前。
export NODE_HOME=/usr/local/node
pathmunge $NODE_HOME/bin

2. PostgreSQL
1). 添加9.x源,rpm源的列表可以在这里找到 http://yum.postgresql.org/repopackages.php#pg93
rpm -i http://yum.postgresql.org/9.3/redhat/rhel-6-i386/pgdg-centos93-9.3-1.noarch.rpm

2). 安装并初始化
yum install postgresql93-server postgresql93-contrib postgresql93-devel
service postgresql-9.3 initdb
chkconfig postgresql-9.3 on

3). 修改配置
cd /var/lib/pgsql/9.3/data/
vim pg_hba.conf
# 将原有 127.0.0.1 这一行中的indent修改为md5,并加下localhost这一行的配置
host    all             all             localhost               md5
host    all             all             127.0.0.1/32            md5
vim postgresql.conf
# 搜索listen_addresses,去掉注释修改localhost为*
listen_addresses = '*'

4). 添加环境变量
vim /etc/profile
export PSQL_HOME=/usr/pgsql-9.3
pathmunge $PSQL_HOME/bin

三、ROR安装配置

1. 安装rvm,
curl -L get.rvm.io | bash -s stable
# 输出以上命令,将会自动进行安装。
sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' /usr/local/rvm/config/db
# 修改源为淘宝镜像,我的rvm安装在/usr/local目录中。完成后重启系统。
# 更多rvm使用可参考 http://ruby-china.org/wiki/rvm-guide

2. 使用rvm安装ruby
rvm install ruby-2.0.0
#修改gem默认源
gem source -a http://ruby.taobao.org/
gem source -r https://rubygems.org/

3. 创建项目以及对应的gemset
#创建项目路径
cd ~
mkdir demo
cd demo
#创建gemset
rvm gemset create demo
rvm gemset use demo
#安装rails
gem install rails

4. 添加postgresql帐号
su postgres
createuser -d demo
psql -d postgres
# 修改demo帐号的密码
ALTER USER demo WITH PASSWORD '123456';
# 退出
\q
 

5. 创建rails项目
rails new . -BT -d postgresql
# -B跳过bundle(后面手动进行),-T跳过test-unit(建议使用RSpec),-d 指定数据库为postgresql

6. 修改rails配置
vim Gemfile
#将第一行修改为淘宝源
source 'http://ruby.taobao.org'
#安装gem
bundle install
#安装pg库的时候会报错,PostgreSQL非系统标准路径,需指定pg_config安装
gem install pg -- --with-pg-config=/usr/pgsql-9.3/bin/pg_config
#编辑数据库配置
vim config/database.yml
# 找到development,修改username为demo,password为第4步指定的密码。如果不需要创建test数据库可以找到test的配置全部注释掉。

development:
  adapter: postgresql
  encoding: unicode
  database: demo_development
  pool: 5
  username: demo
  password: 123456

7. 安装gem
bundle install
#安装到pg库的时候会报错,PostgreSQL非系统标准路径,需指定pg_config安装
gem install pg -- --with-pg-config=/usr/pgsql-9.3/bin/pg_config

8. 创建数据库,启动rails
rake db:create
rails s

经过以上几步,输入http://<ip address>:3000应该可以看到rails的默认页面了。

Avatar_small
SCERT Himachal Prad 说:
2023年9月22日 17:09

HP Board Curriculum is based on the National Curriculum Framework and Provides Opportunities for Students to Achieve Excellence in Learning, HP Board Provides the Syllabus for 1st Class, This new Syllabus are Designed Strategically by a Team of Subject Experts and are Prescribed by the Ministry of Human Resource Development, formerly Ministry of Education, is Responsible for the Development SCERT Himachal Pradesh 1st Class Syllabus 2024 of Human Resources in India, SCERT HP Elementary Level Syllabus for the Children of has been developed with the Supervision of the Directorate of Elementary Education Himachal Pradesh.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter