如何在CentOS上搭建ruby on rails pdf环境

2676人阅读
编程基础(27)
1.&& Ruby on Rails开发环境
1.1.& Windows下安装
在Windows上开始安装Ruby,最容易的方法是利用RubyInstaller安装包进行安装。确保从网址中下载1.8.7或更高版本的Ruby的安装包。目前的最新版本的RubyInstaller安装包为1.9.2-P290。
在你下载RubyInstaller之后,双击运行rubyinstaller-1.9.2-p290.exe,选择“I accept the License”(当然在仔细的阅读它之后),点击“Next”,点击“Browse…”选择安装Ruby的路径,选择“Add Ruby executables to your PATH”,然后点击“Install”à “Finish”。
现在通过选择“开始”--&“运行…”,输入cmd,并且点击“确定”打开命令行窗口(由于Windows操作系统不同打开方式也不一样)。
RubyInstaller包括RubyGems,但是验证你是否运行RubyGems的1.3.6以上版本是重要的。你可以通过下面的命令来验证RubyGtems的版本。
此时,在命令行窗口中会显示的RubyGems版本为1.7.2。
如果需要将RubyGems更新到最新的版本,执行下面的命令:
gem update --system
gem uninstall rubygems-update
接下来,安装SQLite3,从官方网址(http://www.sqlite.org/download.html)下载并且解压两个预编译的二进制文件:
1)访问和修改SQLite数据库的命令行程序(sqlite-shell-win32-x86-3070701)
2)没有TCL绑定的SQLite库的DLL(sqlite-dll-win32-x86-3070701);
拷贝在ZIP压缩包中的文件到D:/Ruby/bin目录中,拷贝文件包括sqlite3.def,sqlite3.dll和sqlite3.exe三个。
现在安装SQLite3的Ruby绑定和Rails,执行下面的命令:
gem install sqlite3-ruby
gem install rails –pre
至此,Windows下的Ruby on Rails的开发环境已经搭建完成。
安装问题解决:
gem install sqlite-ruby
Fetching: sqlite-ruby-2.2.3.gem (100%)
ERROR:& Error installing sqlite-ruby:
&&&&&&& The 'sqlite-ruby' native gem requires installed build tool
Please update your PATH to include build tools or download the Dev
from 'http://rubyinstaller.org/downloads' and follow the instructi
at '/oneclick/rubyinstaller/wiki/Development-Kit'
出错的原始是安装sqlite-ruby时需要编译工具,但是系统中没有,解决办法是到上下载DevKit,并且根据进行安装。
主要的安装步骤如下:
1)如果原来系统中已经安装有旧版本的Dev Kit,则先删除它;
2)下载上面所提到的Dev Kit(DevKit-tdm-32-4.5.2-0-sfx.ex);
3)解压缩下载的7z压缩包到指定的目录,如D:/DevKit(目录不能有空格);
4)进入到解压缩目录中,运行ruby dk.rb init生成config.yml文件,你可以编辑config.yml文件,添加需要安装的或者删除不需要安装的。
5)执行ruby dk.rb review进行确认(可选);
6)执行ruby dk.rb install进行安装;
安装完毕Dev Kit后再此运行ruby install sqlite-ruby成功。
注:在Windows使用dir /w来显示目录,使用erase命令来删除文件。
1.2.& Rails版本选择
先前的命令帮助你安装最新版本的Rails,但是你可能不希望在最新版本下工作。那么你可以使用gem命令列出所有你已经安装的Rails版本:
gem list --loca rails
你也能使用下面的命令来验证你所使用Rails版本:
rails --version
安装其它版本的Rails也可以利用gem命令来完成:
gem install rails --version 3.0.0
现在,有多个Rails的版本被安装到本地计算机。在使用rails命令时,你可以控制使用Rails的版本,命令如下:
rails _3.0.0_ --version
当你创建一个新的应用时这种方法非常方便使用。因为一旦你使用某个版本的rails创建一个应用,那么它将继续使用该版本的rails(即使是最新的版本被安装在系统中),知道你决定更新它为止。为了更新它,只需简单的更新在你应用根目录下的Gemfile中的版本号即可,然后运行bundle install命令。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:700595次
积分:7654
积分:7654
排名:第2179名
原创:106篇
译文:21篇
评论:60条
(1)(5)(11)(7)(2)(3)(6)(22)(8)(2)(26)(6)(29)一次摸索中搭建Ruby on Rails开发环境._Ruby_ThinkSAAS
一次摸索中搭建Ruby on Rails开发环境.
一次摸索中搭建Ruby on Rails开发环境.
内容来源: 网络
关注Ruby on Rails是在去年一个项目偶然机会中看到国外网上视频了解到【找了一下没找到】. 另外一个在Ruby中文社区的看到关于Ruby简介: 其中有一句我现在还记得很清楚"能够几分钟搭建一个WebBlogSystem-多用户博客系统". 因为以前也曾参与和设计过一个多用户博客系统.也知道这其中涉及到的技术难点. Ruby中文社区上这么一说. 倒是无形激发我想去探探究竟的好奇心. 如是乎 就在工作的案头上多了两本:Programing Ruby-(已有中文版)和Ruby On Rails【敏捷的Web开发】.最近正好在InfoQ中文网上看到
台湾开发者-张文细讲解视频. 打算尝试Ruby on Rails上编程.
当然我也是在最近才开始关注Ruby On Rails了解. 发费一个下午时间了解Ruby 语言以及Rails框架.发展 版本更新.语言特点等. 算是在通读了大部分资料 大体了解Ruby on Rails 快捷的Web构建. 但还不单单满足这些文章. 倒是想通过编码例子亲身体验一下Ruby On Rails.特点. 如果你也是一个初=识Ruby on Rails开发者 推荐如下资源:
Ruby Programe 中文官网:
Ruby on Wiki维基百科:
搭建这个环境我是参考Ruby On Rails书上部分配置.[其实配置不全 版本也落后了 书中版本是:1.8.2 我当前配置版本为1.8.6] 准备工作:
A:到ruby Programe 中文官网 下载安装源文件 我的是Windows7系统所以选择Windows安装源文件:根据我选择是一步安装 版本:1.8.6 截图:
B:下载完成后 逐步根据提示安装, 具体安装过程截图如下:
根据提示 下一步:
安装包安装成功后. 运行命令ruby –v,安装成功会显示Ruby的版本号.截图:
ok 初步Ruby安装成功. 安装ruby 成功后 再来安装Rails框架以及Rails需要的其他几件依赖项. 当前Rails框架已经发展到2.3.5版本.
键入命令:"gem install rails --include-dependencies".执行结果:
提示出现一个错误. 即需要一个更新版本的gem[]-RubyGems是标准的Ruby包管理器,它的功能类似于Linux下的apt-get。使用RubyGems可以方便地从远程服务器下载并安装Rails. 根据提示找到下载最新版本的RubyGem.:
下载版本为V1.3.6版本. 目前最新的.下载本地后 解压包 选择根目录下Setup安装文件.运行起来
初始化后 再来键入命令"gem install rails --include-dependencies" 重写安装Rails框架.运行如下:
因为中间安装文件较多. 所以会比较慢. 当时走到infor提示时我以为又出错. 关掉 发现Rails版本没有在cmd查到. 所以这个过程较慢. 耐心等待一下.安装完成后我查看一下Rails框架的版本 查看是否成功.
Rails 2.3.5版本. ok 到目前为止Ruby on Rails开发环境已经安装完成. 因为今天刚刚初始. 安装时显得楞手楞脚. 也算是一次摸索关于Ruby on Rails开发环境搭建.总体来看Ruby on Rails 开发环境还是非常容易的. 两个安装包 一个是23.3M 【Ruby安装】 Rails 框架是7.8M多, 很轻便.
PHP开发框架
开发工具/编程工具
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
让ThinkSAAS更好,把建议拿来。
开发客服微信使用Nginx + unicorn搭建ruby on rails的生产环境
来源:open开发经验库
有三台机器,操作系统都是CentOS 6.3 64位:其中172.16.9.100,安装Nginx服务器;另外的两台172.16.9.101和172.16.9.102安装unicorn,作为RoR的应用服务器。在这里先保证ruby及rails已经在101和102两台机器上配置好,这是前提。如何安装Nginx及RoR的环境就不在这里说了,很多文章都介绍得很详细。
这里假设项目在/var/www/demo_project文件夹中
在101上使用
gem install unicorn 命令安装unicorn。
新建内容为以下的一个文件,需要进行修改的地方请看文件中的中文注释,文件放置到/var/www/demo_project_unicorn.rb,这个文件是对这个项目的生产环境配置
# Sample verbose configuration file for Unicorn (not Rack)
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 4
# Since Unicorn is never exposed to outside clients, it does not need to
# run on the standard HTTP port (80), there is no reason to start Unicorn
# as root unless it's from system init scripts.
# If running the master process as root and the workers as an unprivileged
# user, do this to switch euid/egid in the workers (also chowns logs):
# user "unprivileged_user", "unprivileged_group"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/var/www/demo_project" # available in 0.94.0+ 在这里修改为项目所在目录
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/var/tmp/.unicorn.sock", :backlog =& 64
listen 19527, :tcp_nopush =& true
#端口号,NginX需要用到此端口号
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 120
# feel free to point this anywhere accessible on the filesystem
pid "/usr/tmp/demo_project/pids/unicorn.pid"
#pid文件的位置,可以自己设置,注意权限
# By default, the Unicorn logger will write to stderr.
# Additionally, ome applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path "/usr/tmp/demo_project/log/unicorn.stderr.log"
#错误日志的位置,自己设置,注意权限
stdout_path "/usr/tmp/demo_project/log/unicorn.stdout.log"
#输出日志的位置,自己设置,注意权限
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
# /faq.html#adapt_apps_for_cow
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
# Enable this flag to have unicorn test client connections by writing the
# beginning of the HTTP headers before calling the application.
# prevents calling the application for connections that have disconnected
# while queued.
This is only guaranteed to detect clients on the same
# host unicorn runs on, and unlikely to detect disconnects even on a
# fast LAN.
check_client_connection false
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
# The following is only recommended for memory/DB-constrained
# installations.
It is not needed if your system can house
# twice as many worker_processes as you have configured.
# # This allows a new master process to incrementally
# # phase out the old master process with SIGTTOU to avoid a
# # thundering herd (especially in the "preload_app false" case)
# # when doing a transparent upgrade.
The last worker spawned
# # will then kill off the old master process with a SIGQUIT.
# old_pid = "#{server.config[:pid]}.oldbin"
# if old_pid != server.pid
begin
sig = (worker.nr + 1) &= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# end
# Throttle the master from forking too quickly by sleeping.
# to the implementation of standard Unix signal handlers, this
# helps (but does not completely) prevent identical, repeated signals
# from being lost when the receiving process is busy.
# sleep 1
after_fork do |server, worker|
# per-process listener ports for debugging/admin/migrations
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries =& -1, :delay =& 5, :tcp_nopush =& true)
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis.
TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
然后创建一个shell文件,内容如下,这个文件命名为/var/www/unicorn.sh
UNICORN=/usr/local/ruby/bin/unicorn_rails
killall -9
unicorn_rails
$UNICORN -c /var/www/demo_project_unicorn.rb -D -E production 
其中第一行,指明unicorn的安装位置,unicorn安装成功后,是和ruby,rails等可执行文件是在同一个文件夹中的。第二行,关闭unicorn_rails的进程。第三行,根据-c参数后的配置,在生产环境中启动项目。执行这个文件就能启动unicorn服务器。
另外的一台主机102的配置,也与101相同。unicorn的配置也就完成了。下面开始NginX的配置
在/usr/local/nginx/conf/nginx.conf中添加如下的配置信息,具体意思见中文注释
upstream demo_project_backend {
#连接两台RoR unicorn服务器
server 172.16.9.101:19527;
server 172.16.9.102:19527;
server {
default_
server_name
server {
server_name
www. ;
#access_log
logs/host.access.
proxy_connect_timeout 500s;
proxy_read_timeout 500s;
proxy_send_timeout 500s;
#将对的请求,转到两台主机上 
location / {
index.html index.
proxy_pass http://demo_project_
# redirect server error pages to the static page /50x.html
error_page
500 502 503 504
/50x.
location = /50x.html {
来自:http://my.oschina.net/mogralee/blog/;
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动在阿里云 (aliyun) 服务器上搭建Ruby On Rails环境
投稿:hebedich
字体:[ ] 类型:转载 时间:
最近总是在配置阿里云的服务器,遇到不少问题,现小结一下,供大家参考~~
1、阿里云的一键安装web全环境
下载一键安装web全环境 sh.zip 压缩包
上传至服务器,解压、执行脚本,具体步骤详见这里
$ mv sh.zip /home/tmp/ & cd /home/tmp
$ unzip sh.zip
$ chmod -R 777 sh & cd sh
# 任意选择一种方法执行脚本
$ ./install.sh
$ ./install_nginx_xxx.sh
$ ./install_mysql_xxx.sh
2、安装RVM与指定的Ruby版本
安装RVM与指定的Ruby版本
$ curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
# 注意安装完成后,根据提示执行source命令
查看是否安装成功
ruby 1.9.3p448 ( revision 41675) [i686-linux]
更换 gem source,提高gem下载速度
$ gem source -r https://rubygems.org/ $ gem source -a http://ruby.taobao.org
3、安装git、编译 javascript 运行时环境 node.js
安装git工具
$ yum install git
编译node.js(javascript运行时环境)
$ git clone /joyent/node.git
$ ./configure && make && make install
#如果无法编译,说名需要叫python升级到2.6或2.7
#如果缺少bz2,需要yum install bzip2-devel后,重新编译python
克隆你的项目
$ git clone path/to/your/project.git
# 安装项目指定gem包
$ cd path/to/your/project
$ bundle install
4、配置unicorn文件并运行生产环境
查看unicorn配置实例 config/unicorn.rb
启动unicron生产环境
$ unicorn_rails -c config/unicorn.rb -E production -D
关闭unicorn进程
$ kill -9 $(cat tmp/pids/unicorn.pid )
5、配置nginx虚拟主机
添加nginx虚拟主机配置
$ vim /path/to/your/nginx/vhosts/xxxx.conf
配置内容(将汉字替换成相应有效内容):
upstream unicorn_server
server unix:项目根目录/tmp/sockets/unicorn.sock fail_timeout=0;
server_name 域名;
root 项目根目录/
location /
proxy_set_header Host $
proxy_set_header X-Forwarded-Host $
proxy_set_header X-Forwarded-Server $
proxy_set_header X-Real-IP $remote_
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_
if (!-f $request_filename) {
proxy_pass http://unicorn_
location ~ ^/(assets)/
add_header Cache-C
低内存服务器添加内存释放任务
$ vim /etc/crontab
在最后一行添加如下内容(每天凌晨1点释放内存):
00 1 * * * echo 3 & /proc/sys/vm/drop_caches
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具在阿里云 (aliyun) 服务器上搭建Ruby On Rails环境 - Ruby - 自习教室
在阿里云 (aliyun) 服务器上搭建Ruby On Rails环境
1、阿里云的一键安装web全环境下载一键安装web全环境 sh zip 压缩包上传至服务器,解压、执行脚本,具体步骤详见这里$ mv sh zip hom
1、阿里云的一键安装web全环境
下载一键安装web全环境 sh.zip 压缩包
上传至服务器,解压、执行脚本,具体步骤详见这里
$ mv sh.zip /home/tmp/ & cd /home/tmp
$ unzip sh.zip
$ chmod -R 777 sh & cd sh
# 任意选择一种方法执行脚本
$ ./install.sh
$ ./install_nginx_xxx.sh
$ ./install_mysql_xxx.sh
2、安装RVM与指定的Ruby版本
安装RVM与指定的Ruby版本
$ curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
# 注意安装完成后,根据提示执行source命令
查看是否安装成功
ruby 1.9.3p448 ( revision 41675) [i686-linux]
更换 gem source,提高gem下载速度更多
$ gem source -r https://rubygems.org/ $ gem source -a http://ruby.taobao.org
3、安装git、编译
运行时环境 node.js
安装git工具
$ yum install git
编译node.js(javascript运行时环境)
$ git clone /joyent/node.git
$ ./configure && make && make install
#如果无法编译,说名需要叫升级到2.6或2.7
#如果缺少bz2,需要yum install bzip2-devel后,重新编译python
克隆你的项目
$ git clone path/to/your/project.git
# 安装项目指定gem包
$ cd path/to/your/project
$ bundle install
4、配置unicorn文件并运行生产环境
查看unicorn配置实例 config/unicorn.rb
启动unicron生产环境
$ unicorn_rails -c config/unicorn.rb -E production -D
关闭unicorn进程
$ kill -9 $(cat tmp/pids/unicorn.pid )
5、配置nginx虚拟主机
添加nginx虚拟主机配置
$ vim /path/to/your/nginx/vhosts/xxxx.conf
配置内容(将汉字替换成相应有效内容):
upstream unicorn_server
server unix:项目根目录/tmp/sockets/unicorn.sock fail_timeout=0;
server_name 域名;
root 项目根目录/
location /
proxy_set_header Host $
proxy_set_header X-Forwarded-Host $
proxy_set_header X-Forwarded-Server $
proxy_set_header X-Real-IP $remote_
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_
if (!-f $request_filename) {
proxy_pass http://unicorn_
location ~ ^/(assets)/
add_header Cache-C
低内存服务器添加内存释放任务
$ vim /etc/crontab
在最后一行添加如下内容(每天凌晨1点释放内存):
00 1 * * * echo 3 & /proc/sys/vm/drop_caches
相关热词搜索:
频道总排行
频道本月排行

我要回帖

更多关于 ruby on rails 的文章

 

随机推荐