环境:CentOS 6.6
ruby是开发语音,rails是开发框架,例如:DoitPHP是PHP的开发框架一样
官网安装方式:http://rubyonrails.org/download/
[root@CentOS ~]# yum -y groupinstall "Development Tools" [root@CentOS ~]# yum -y install libyaml* ruby-devel [root@CentOS software]# wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p448.tar.gz
[root@CentOS software]# tar -zxvf ruby-1.9.3-p448.tar.gz [root@CentOS software]# cd ruby-1.9.3-p448 [root@CentOS ruby-1.9.3-p448]# ./configure --prefix=/usr/local/ruby [root@CentOS ruby-1.9.3-p448]# make [root@CentOS ruby-1.9.3-p448]# make install [root@CentOS ~]# tail -1 /etc/profile export PATH=/usr/local/ruby/bin:$PATH [root@CentOS ~]# ruby -v ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux] [root@CentOS ~]#
[root@CentOS software]# tar -zxvf rubygems-1.8.24.tgz [root@CentOS software]# cd rubygems-1.8.24 [root@CentOS rubygems-1.8.24]# ruby setup.rb [root@CentOS ~]# gem -v 1.8.24 [root@CentOS ~]#
[root@CentOS ~]# yum -y install zlib zlib-devel [root@CentOS ~]# cd /software/ruby-1.9.3-p448/ext/zlib/
[root@CentOS zlib]# ruby ./extconf.rb [root@CentOS zlib]# make &&make install
更换gem源
[root@CentOS ~]# gem sources list /usr/local/ruby/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. *** CURRENT SOURCES *** http://rubygems.org/ [root@CentOS ~]# gem sources --remove http://rubygems.org/
[root@CentOS ~]# yum -y install openssl openssl-devel [root@CentOS ~]# cd /software/ruby-1.9.3-p448/ext/openssl/ [root@CentOS openssl]# ruby extconf.rb
#make时报下面的错误:
修改ossl_pkey_ec.c文件,因为:由redhat新版本默认openssl的配置变更取消了对EC_xx的支持,所以出现该错误
#if !defined(OPENSSL_NO_EC2M)
#endif
再次执行就OK了
[root@CentOS openssl]# make && make install
添加新的gem源:
[root@CentOS openssl]# gem sources -a https://ruby.taobao.org/ [root@CentOS ~]# gem sources list /usr/local/ruby/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. *** CURRENT SOURCES *** https://ruby.taobao.org/ [root@CentOS ~]#
[root@CentOS ~]# gem install rdoc [root@CentOS ~]# gem install bundle [root@CentOS ~]# gem install spring [root@CentOS ~]# gem install rails //很慢。。 [root@CentOS ~]# rails -v Rails 4.2.5 [root@CentOS ~]#
[root@CentOS ~]# gem install rake -v '10.4.2' [root@CentOS ~]# yum -y install sqlite-devel [root@CentOS ~]# gem install sqlite3
新建一个项目:
[root@CentOS ~]# rails new HelloWorld
这时会因为环境原因而导致创建失败,可以通过bundle install执行解决
[root@CentOS ~]# cd HelloWorld/ [root@CentOS HelloWorld]# head -1 Gemfile source 'https://ruby.taobao.org/' [root@CentOS HelloWorld]# [root@CentOS HelloWorld]# bundle install -V [root@CentOS ~]# rails new HelloWorld
[root@CentOS ~]# cd HelloWorld/ [root@CentOS HelloWorld]# rails server //如果执行报错,需要升级rubygems版本 [root@CentOS ~]# gem install rubygems-update [root@CentOS ~]# update_rubygems [root@CentOS ~]# gem -v 2.5.0 [root@CentOS ~]#
再次执行rails server报下面的错误
[root@CentOS HelloWorld]# grep therubyracer Gemfile |grep -v ^# gem 'therubyracer' [root@CentOS HelloWorld]# bundle install -V [root@CentOS HelloWorld]# rails server -b 172.24.17.120 -p 2000 -d Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring. => Booting WEBrick => Rails 4.2.5 application starting in development on http://172.24.17.120:2000 => Run `rails server -h` for more startup options [root@CentOS HelloWorld]# [root@CentOS ~]# netstat -tunlp|grep 2000 tcp 0 0 172.24.17.120:2000 0.0.0.0:* LISTEN 21417/ruby [root@CentOS ~]#
视频:Ruby在Linux下搭建Ruby On Rails开发环境:
http://v.youku.com/v_show/id_XMzk2MDI5MDMy.html
本文出自 “鹏城-酱油瓶” 博客,谢绝转载!