Ubuntu搭建Ruby on Rails環境

安裝Ruby

因爲Ubuntu的apt包管理器的ruby版本過舊,故考慮從源碼編譯安裝。這裏以安裝ruby2.3.0爲例:node

sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz
tar -xvzf ruby-2.3.0.tar.gz
cd ruby-2.3.0/
./configure
make
sudo make install

安裝完成後,咱們能夠查看其版本:linux

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [i686-linux]

安裝sqlite3

sudo apt-get install sqlite3 libsqlite3-dev

安裝Rails

因爲GFW的緣故,ruby默認的gem源rubygems.org沒法訪問,故須要先換源。sql

查看當前的gem源:ruby

$ gem sources -l
*** CURRENT SOURCES ***

https://rubygems.org/

換源:服務器

$ gem sources -r https://rubygems.org/
https://rubygems.org/ removed from sources
$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
$ gem sources -l
*** CURRENT SOURCES ***

https://ruby.taobao.org/

安裝Rails:app

sudo gem install rails

安裝完成後查看其版本:ui

$ rails --version
Rails 4.2.5.2

修改Gemfile

編輯Gemfile:spa

sudo vi /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.5.2/lib/rails/generators/rails/app/templates/Gemfile

將第一行code

source 'https://rubygems.org'

改成:server

source 'https://ruby.taobao.org/'

安裝JavaScript 運行時

這裏選擇安裝NodeJS:

sudo apt-get install nodejs

創建Rails工程

rails new demo

進入文件夾,啓動服務器:

cd demo/
rails server

相關文章
相關標籤/搜索