Ubuntu 环境停配置安装Ruby on Rails

Ubuntu 环境下配置安装Ruby on Rails

最近研究Ruby on Rails,初期配置,看了很多教程,没有一篇成功的,最终几个结合着搞出来了,记录一下。本文主要以http://ruby-china.org/wiki/install-rails-on-ubuntu-12-04-server为主,然后结合了一些自己配置时遇到问题的修复,欢迎大家一起讨论,如果有问题我会及时修改的,Ruby On Rails新手入门能用的教程实在是太少了


安装必要的三方库


sudo apt-get install -y wget vim build-essential openssl libreadline6 libreadline6-dev libmysqlclient-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev libcurl4-openssl-dev autoconf automake libtool imagemagick libmagickwand-dev libpcre3-dev nodejs libpq-dev 

安装 Ruby, Rails 及相关

安装 RVM

$ \curl -L https://get.rvm.io | bash -s stable
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc
$ source ~/.bashrc
$ rvm -v

安装 Ruby

如果你是国内服务器,推荐将 RVM 的安装源替换成 Taobao 的镜像服务器,这样安装能更快!

$ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db

用 RVM 安装 Ruby:

$ rvm pkg install readline openssl

这里会有问题,说是auto_conf的问题这里我参考了http://*.com/questions/8176076/how-to-get-readline-support-in-irb-using-rvm-on-ubuntu-11-10,输入了

$ rvm --skip-autoreconf pkg install readline

我们atuo_conf,然后就没有error了,ok, go on.

$ rvm install 2.0.0
$ rvm use 2.0.0 --default
$ ruby -v
ruby 2.0.0p247

国内服务器推荐替换 RubyGems 的到淘宝镜像:

$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***

http://ruby.taobao.org

安装 Rails

$ gem install rails
$ rails -v
Rails 4.0.0
这里会有很多这样的提示,这个都是一些warning,所以可以不管它。但是感觉很是不爽,尽量去修复下吧。

unable to convert "\xF5" from ASCII-8BIT to UTF-8 for guides/assets/images/nav_arrow.gif, skipping


在这个网页下http://*.com/questions/18235293/ruby-on-rails-unable-to-convert-x89-from-ascii-8bit-to-utf-8-for-xxx-xxxx-x

他说是需要更新下rdoc,

You need to update / install a version of the rdoc gem that supports the conversion. Then these errors won't appear during generation of the documentation when you install rails or when you regenerate the documentation.

gem install rdoc

Then to regenerate the documentation

gem rdoc --all --overwrite

这基本上就算完成了。

另外,rails new test2时,总是卡死在bundle install 上,这是因为rails会在每次创建一个项目他都会自动运行bundle install , 然后就卡死了。。。

解决办法:

rails new demo --skip-bundle  通过它新建一个项目

cd 进去

然后再运行bundle install

修改Gemfile ,修改source 'https://rubygems.org'为source 'http://ruby.taobao.org '


输入 rails s,有人会有问题,(上次配置出现了,这次重装配置没有出现诶。)问题说的时JavaScript的问题,它是因为有个软件是不默认安装的,因为系统不同,所以需要你自己装下,然后就ok 了,可能时Nodejs,假如我出现了,再更新这个地方。

然后rails s,启动。。。。哇哈哈,一切搞定