Ruby on Rails with Fedora

Install RVM and Ruby

官方網站 https://rvm.io

在終端機輸入
這個是只有先安裝 RVM

\curl -L https://get.rvm.io | bash -s stable

而這個是安裝 RVM 且安裝最新版的 Ruby

\curl -L https://get.rvm.io | bash -s stable --ruby

訊息大概會像下面這樣

[negaihoshi@localhost ~]$ \curl -L https://get.rvm.io | bash -s stable --ruby
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   184  100   184    0     0    120      0  0:00:01  0:00:01 --:--:--   120
100 14557  100 14557    0     0   5870      0  0:00:02  0:00:02 --:--:--  5870
Please read and follow further instructions.
Press ENTER to continue.
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   124  100   124    0     0    111      0  0:00:01  0:00:01 --:--:--   111
100 1083k  100 1083k    0     0   233k      0  0:00:04  0:00:04 --:--:--  457k

Installing RVM to /home/negaihoshi/.rvm/
    Adding rvm PATH line to /home/negaihoshi/.bashrc /home/negaihoshi/.zshrc.
    Adding rvm loading line to /home/negaihoshi/.bash_profile /home/negaihoshi/.zprofile.
Installation of RVM in /home/negaihoshi/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/negaihoshi/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# negaihoshi,
#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne

# In case of problems:
#      run and read: rvm notes
#         read docs: http://rvm.io/
#        talk to us: http://webchat.freenode.net/?channels=rvm (http://freenode.net/faq.shtml#plusr)
#   read cheatsheet: http://cheat.errtheblog.com/s/rvm
#  watch screencast: http://screencasts.org/episodes/how-to-use-rvm
# open a bug report: https://github.com/wayneeseguin/rvm/issues

rvm 1.22.3 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

Searching for binary rubies, this might take some time.
No binary rubies available for: fedora/19/x86_64/ruby-2.0.0-p247.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for fedora.
Installing requirements for fedora.
Installing required packages: patch, patch, readline-devel, zlib-devel, libyaml-devel, libffi-devel, openssl-devel, autoconf, automake, libtoolnegaihoshi password required for 'yum install -y patch patch readline-devel zlib-devel libyaml-devel libffi-devel openssl-devel autoconf automake libtool': 

這邊的話 RVM 自動偵測你的 Fedora 版本需要哪些套件,這裡需要管理員權限要輸入 Root Password。

......................................................................................................................................................
Requirements installation successful.
Installing Ruby from source to: /home/negaihoshi/.rvm/rubies/ruby-2.0.0-p247, this may take a while depending on your cpu(s)...
ruby-2.0.0-p247 - #downloading ruby-2.0.0-p247, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10.3M  100 10.3M    0     0   509k      0  0:00:20  0:00:20 --:--:--  1572
ruby-2.0.0-p247 - #extracting ruby-2.0.0-p247 to /home/negaihoshi/.rvm/src/ruby-2.0.0-p247
ruby-2.0.0-p247 - #extracted to /home/negaihoshi/.rvm/src/ruby-2.0.0-p247
Applying patch /home/negaihoshi/.rvm/patches/ruby/2.0.0/logging.patch....
ruby-2.0.0-p247 - #configuring.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
ruby-2.0.0-p247 - #post-configuration
ruby-2.0.0-p247 - #compiling..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
ruby-2.0.0-p247 - #installing.................................................................................................................................................................................................................................................................................................
Retrieving rubygems-2.0.7
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  329k  100  329k    0     0   405k      0 --:--:-- --:--:-- --:--:--  405k
Extracting rubygems-2.0.7 ...
Removing old Rubygems files...
Installing rubygems-2.0.7 for ruby-2.0.0-p247..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Installation of rubygems completed successfully.
Saving wrappers to '/home/negaihoshi/.rvm/wrappers/ruby-2.0.0-p247'........

ruby-2.0.0-p247 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-2.0.0-p247 - #importing default gemsets, this may take time.......................
Install of ruby-2.0.0-p247 - #complete 
Creating alias default for ruby-2.0.0-p247.
Recording alias default for ruby-2.0.0-p247.
Creating default links/files
Saving wrappers to '/home/negaihoshi/.rvm/bin'........

  * To start using RVM you need to run `source /home/negaihoshi/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

RVM 安裝完成,最後這邊提示在終端機輸入

    source /home/negaihoshi/.rvm/scripts/rvm

完成安裝\0.0/


安裝 Rails

在終端機中輸入

gem install rails

就可以安裝拉\0.0/
應該是不會有什麼大問題可以正常安裝完成。

接下來測試 Rails Project 能不能正常使用,在終端機輸入

rails new testRails

他會簡單生成 Rails 的檔案架構,然後自動 bundle install 一次,如果可以正常 bundle 完成就沒什麼問題,我這邊有發生錯誤,我的 Rails 版本是 4.0.0 ,它的 sqlite 安裝不起來。
大致上如下:

Installing sqlite3 (1.3.8) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /home/negaihoshi/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb 
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/home/negaihoshi/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
  --with-sqlite3-dir
  --without-sqlite3-dir
  --with-sqlite3-include
  --without-sqlite3-include=${sqlite3-dir}/include
  --with-sqlite3-lib
  --without-sqlite3-lib=${sqlite3-dir}/
  --enable-local
  --disable-local


Gem files will remain installed in /home/negaihoshi/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8 for inspection.
Results logged to /home/negaihoshi/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/ext/sqlite3/gem_make.out

An error occurred while installing sqlite3 (1.3.8), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.8'` succeeds before bundling.

上面有錯誤提示,這邊提示說安裝一下 sqlite-devl,所以就安裝一下吧~
在終端機輸入

yum install sqlite-devel

安裝完成後重新 bundle 在終端機中輸入

bundle install

這次應該就可以安裝完成拉。
最後輸入

rails server
或是
rails s

運行 server 就可以看到網站拉。

comments powered by Disqus