安装ruby
首先不再使用ubuntu的apt-get安装ruby,自己编译安装,这样虽然不能使用ubuntu系统apt-get的升级功能对ruby进行升级,但胜在自由度最高,想怎么折腾就怎么折腾.
到 /zh_CN/downloads/ 下载ruby 1.9.1的源代码.
Ruby代码
#解压文件
tar vfxz ruby-1.9.
#进入解压后的文件夹
cd ruby-1.9.1-p0/
#编译源码,在编译之前,应该先对/usr/local/ruby-1.9.1文件夹设置权限.
./configure --prefix=/usr/local/ruby-1.9.1
#大名鼎鼎的 make 和 install
make && make install
#设置PATH路径,把自己安装的ruby放在系统PATH前面,避免调用操作系统自带的ruby
export PATH=/usr/local/ruby-1.9.1/binPATH
#我在 ~/.profile 文件中增加了这样的代码:
if [ -d "/usr/local/ruby-1.9.1/bin" ] ; then
PATH="/usr/local/ruby-1.9.1/binPATH"
fi
然后 注销 再登陆一次.
#如无意外
ruby -v
#ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
#ruby 1.9.1安装成功了.
#解压文件
tar vfxz ruby-1.9.
#进入解压后的文件夹
cd ruby-1.9.1-p0/
#编译源码,在编译之前,应该先对/usr/local/ruby-1.9.1文件夹设置权限.
./configure --prefix=/usr/local/ruby-1.9.1
#大名鼎鼎的 make 和 install
make && make install
#设置PATH路径,把自己安装的ruby放在系统PATH前面,避免调用操作系统自带的ruby
export PATH=/usr/local/ruby-1.9.1/binPATH
#我在 ~/.profile 文件中增加了这样的代码:
if [ -d "/usr/local/ruby-1.9.1/bin" ] ; then
PATH="/usr/local/ruby-1.9.1/binPATH"
fi
然后 注销 再登陆一次.
#如无意外
ruby -v
#ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
#ruby 1.9.1安装成功了.
自己编译安装的好处就是,当下次ruby 1.9.2升级的时候,如果你不想升级,你完成可以无视.如果你想尝鲜,你可以下载ruby 1.9.2,然后重复一下上面的功能,不同的只是把它安装到ruby-1.9.2文件.再把ruby-1.9.2/bin路径设置到PATH前面,完全是无痛升级,并且可以自由切换;如果你想删除这个版本,
只要 rm -Rf ruby-1.9.1,绝不会留下任何疤痕,非常干净,爽就一个字.
升级到ruby 1.9.1后,不用再另外单独安装 rubygems 了,在ruby 1.9.1下,rubygems已经是默认的ruby包管理程序,查看一下ruby-1.9.1/bin,你会发现gem已经静静地在那里了.
Ruby代码
#执行
gem -v
#1.3.1,gem的版本
#再执行
gem list
#你会发现什么都没有,当然啦,这个新的ruby,你还没有安装任何gem包呢.
#执行
gem -v
#1.3.1,gem的版本
#再执行
gem list
#你会发现什么都没有,当然啦,这个新的ruby,你还没有安装任何gem包呢.
安装Rails
gem install rails -y #从远程安装Rails和所有的依赖.正宗的一键安装,方便快捷.将会安装如下的gem:
syntaxerror是什么错误Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed active
resource-2.3.2
Successfully installed rails-2.3.2
6 gems installed
Installing ri documentation for activesupport-2.
Installing ri documentation for activerecord-2.
Installing ri documentation for actionpack-2.
Installing ri documentation for actionmailer-2.
Installing ri documentation for activeresource-2.
再次执行 gem list,可以看到如下信息:
*** LOCAL GEMS ***
actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
rails (2.3.2)
rake (0.8.4)
Rails 2.3.2升级成功了.
下面看看怎么把已有项目升级到当前的Rails版本(2.3.2)
我是使用Nebeans 6.5进行开发的,顺便把Netbeans 升级到6.5.1版本.
在Netbeans选中你的项目,右键,选择 Properties ,把 Ruby Platform改为 Ruby 1.9.1 p0就可以了.(如果没有,请增加).
直接使用 rake rails:update 任务进行升级,结果却令我失望了,加上 --trace 选项可以看到,在新版本下boot.rb文件会报错,错误信息如下:
Ruby代码
config/boot.rb:86:in `load_rubygems'
config/boot.rb:52:in `load_initializer'
config/boot.rb:38:in `run'
config/boot.rb:11:in `boot!'
config/boot.rb:109:in `<top (required)>'
Rakefile:4:in `require'
Rakefile:4:in `<top (required)>'
config/boot.rb:86:in `load_rubygems'
config/boot.rb:52:in `load_initializer'
config/boot.rb:38:in `run'
config/boot.rb:11:in `boot!'
config/boot.rb:109:in `<top (required)>'
Rakefile:4:in `require'
Rakefile:4:in `<top (required)>'
我也不想去查错误,于是新建了一个Rails项目(建一个空目录,进行目录下,然后 rails .),把新项目的 boot.rb 文件拷贝过来,然后执行 rake rails:update 成功了!
有一个特别的地方,我在一个rb文件的一个正则表达式中使用了全角的逗号,居然不能启动服务器,报如下错误: invalid multibyte char (US-ASCII) (SyntaxError).先把这个去掉,保证能启动再说.
还是不能启动,提示:no such file to load -- openssl (RuntimeError) . 其实这个提示误人不少,一般都以为没有安装openssl的ruby gem,如果安装的是系统自带版的ruby的话,要执行的是: sudo apt-get install libopenssl-ruby1.9
由于我是自己编译的ruby版本,所以要这样做: Ruby代码
1. sudo apt-get install openssl libssl-dev
2. cd ruby_source_dir(就是编译ruby的目录)/ext/openssl
3. ruby extconfig.rb
4. make && make install
1. sudo apt-get install openssl libssl-dev
2. cd ruby_source_dir(就是编译ruby的目录)/ext/openssl
3. ruby extconfig.rb
4. make && make install
还是不能升级到ruby 1.9.1,因为我使用中的一个重要的gem:ferret 现在不支持ruby 1.9.1.所以只好继续使用 ruby 1.8.7,但是rails升级到2.3.2.
在ubuntu 下升级 rails.
由于rails 2.3.2要求rubygem的版本是1.3.1,在我的系统中的gem的版本是1.2.0,必须得升级.由于是使用ubuntu 源安装的gem,因此不能使用 gem update --system
到 下载rubygems 1.3.1版本.
解压下,进
行解压目录,执行一下 sudo ruby setup.rb , 再执行一下 gem -v,发现已经升级到了1.3.1版本.
gem update rails 升级就完成了.
gem升级后,gem list为空,要重新安装需要的gem包.
项目升级的一个问题:
自己对ActiveRecord的一个open class增强(opar.rb文件中)
未升级前放在 config/envirment.rb 文件的 Rails::Initializer.run do |config| require File.join(File.dirname(__FILE__),'..', 'lib','extend','opar') #加载我的增强代码 end 块当中,升级后启动出错:
Ruby代码
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:416:in `initialize_database': undefined method `configurations=' for ActiveRecord::Base:Class (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:141:in `process'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `send'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `run'
from /home/yanghuan/dev/my_project/config/environment.rb:13
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/yanghuan/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /home/yanghuan/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:5
21:in `new_constants_in'
from /home/yanghuan/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:416:in `initialize_database': undefined method `configurations=' for ActiveRecord::Base:Class (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:141:in `process'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `send'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `run'
from /home/yanghuan/dev/my_project/config/environment.rb:13
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/yanghuan/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /home/yanghuan/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/yanghuan/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:
in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
修改后:在 config/envirment.rb 文件的 Rails::Initializer.run do |config| end require File.join(File.dirname(__FILE__),'..', 'lib','extend','opar') #加载我的增强代码.
出现这个错误的原因是:在opar.rb中修改了ActiveRecord::Base类的定义,而在Rails::Initializer.run do |config| ... end执行完成之前,Rails还没有加载ActiveRecord,故而出错.
代码放在block外面了.这下还启动了.
至此升级顺利完成.
gem uninstall Rails
gem uninstall Rake
gem uninstall Actionwebservice
gem uninstall Actionmailer
gem uninstall Actionpack
gem uninstall Activesu
提示Gem::InstallError,代表已经删除。重新安装rails:gem update rails -v 2.3.2 --no-ri --no-rdoc(装不了的情况可能是网络原因)
Rake
Java代码 收藏代码
rake db:fixtures:load
# 载入fixtures到当前环境的数据库
# 载入指定的fixtures使用FIXTURES=x,y
rake db:migrate
# 迁移数据库通过在db/migrate目录下的脚本.可以指定版本号通过VERSION=x
rake db:schema:dump
# 创建一个db/schema.rb文件,通过AR能过够支持任何数据库去使用
rake db:schema:load
# 载入一个schema.rb文件进数据库
rake db:sessions:clear
# 清空sessions表
rake db:sessions:create
# 用CGI::Session::ActiveRecordStore创建一个sessions表为用户
rake db:structure:dump
# 导出数据库结构为一个SQL文件
rake db:test:clone
# 重新创建一个测试数据库从当前环境数据库中
rake db:test:clone_structure
# 重新创建测试数据库从开发模式数据库
rake db:test:prepare
# 准备测试数据库并在入schema
rake db:test:purge
# 清空测试数据库
rake doc:app
# 创建HTML文件的API Documentation
rake doc:clobber_app
# 删除Documentation
rake doc:clobber_plugins
# 删除 plugin Documentation
rake doc:clobber_rails
# 删除Documentation
rake doc:plugins
# 产生Documation为所有安装的plugins
rake doc:rails
# 创建HTML文件的API Documentation
rake doc:reapp
# 强制重新创建HTML文件的API Documentation
rake doc:rerails
# 强制重新创建HTML文件的API Documentation
rake log:clear
# 清空目录log/下的所有日志文件
rake rails:freeze:edge
# Lock this application to latest Edge Rails. Lock a specific revision with REVISION=X
[an error occurred while processing this directive]
rake rails:freeze:gems
# Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze
# Unlock this application from freeze of gems or edge and return to a fluid use of system gems
rake rails:update
# Update both scripts and public/javascripts from Rails
rake rails:
update:javascripts
# Update your javascripts from your current rails install
rake rails:update:scripts
# Add new scripts to the application script/ directory
rake stats
# Report code statistics (KLOCs, etc) from the application
rake test
# Test all units and functionals
rake test:functionals
# Run tests for functionalsdb:test:prepare
rake test:integration
# Run tests for integrationdb:test:prepare
rake test:plugins
# Run tests for pluginsenvironment
rake test:recent
# Run tests for recentdb:test:prepare
rake test:uncommitted
# Run tests for uncommitteddb:test:prepare
rake test:units
# Run tests for unitsdb:test:prepare
rake tmp:cache:clear
# 清空tmp/cache目录下的所有文件
rake tmp:clear
# 清空session, cache, 和socket文件从tmp/目录
rake tmp:create
# 为sessions, cache, and sockets创建tmp/目录
rake tmp:sessions:clear
# 清空所有在tmp/sessions目录下的文件
rake tmp:sockets:clear
# 清空所有在tmp/sessions 目录下的ruby_sess.* 文件
Scripts
Java代码 收藏代码
script/about
# 输出当前环境信息
script/breakpointer
# 启动断点server
script/console
# 启动交换式的Rails控制台
script/destroy
# 删除通过generators创建的文件
script/generate
# -> generators
script/plugin
# -> Plugins
script/runner
# 执行一个任务在rails上下文中
script/server
# 启动开发模式服务器localhost:3000
//以下几个不知道怎么去使用
script/performance/profiler
script/performance/benchmarker
script/process/reaper
script/process/spawner
Generators
Java代码 收藏代码
ruby script/generate model ModelName
ruby script/generate controller ListController show edit
ruby script/generate scaffold ModelName ControllerName
ruby script/generate migration AddNewTable
ruby script/generate plugin PluginName
ruby script/generate mailer Notification lost_password signup
ruby script/generate web_service ServiceName api_one api_two
ruby script/generate integration_test TestName
ruby script/generate session_migration
可选项:
-p, --pretend Run but do not make any changes.
-f, --force Overwrite files that already exist.
-s, --skip Skip files that already exist.
-q, --quiet Suppress normal output.
-t, --backtrace Debugging: show backtrace on errors.
-h, --help Show this help message.
-c, --svn Modify files with subversion. (Note: svn must be in path)
Plugins
Java代码 收藏代码
script/plugin discover
# discover plugin repositories
script/plugin list
# list all available plugins
script/plugin install where
# install the a€wherea€? plugin
script/plugin install -x where
# install where plugin as SVN external
script/plugin install invisible.ch/projects/plugins/where
script/pl
ugin update
# update installed plugins
script/plugin source
# add a source repository
script/plugin unsource
# removes a source repository
script/plugin sources
# lists source repositories
这个非常好解决,首先进入redmine目录下进行操作,gem list -v查看你的rake版本,如果存在0.9.*版本的就输入gem uninstall -v=0.9.* rake(*代表版本号是几就填写几eg:0.9.2),然后会提示卸载成功,然后输入gem install -v=0.8.7 rake,会提示安装成功,还有如果遇到rack~>1.0.1也同样处理,先执行gem list查看当前rack版本然后执行gem uninstall -v=1.0.1 rack进行卸载,然后执行gem install -v=1.1.0 rack就可以更新这个版本了,如果遇到缺少i18n 0.4.2 gem 就到网上下载一个文件,然后拷贝到redmine目录,再执行gem install -v=0.4.2 i18n就可以了都弄好后执行rake db;命令就可以创建数据库链接了。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论