Ubuntu Ruby On Rails

Ruby安裝

官網git

sudo apt-get install ruby-full

Installers

If the version of Ruby provided by your system or package manager is out of date, a newer one can be installed using a third-party installer. Some of them also allow you to install multiple versions on the same systemgithub

第三方工具容許你安裝多個不一樣版本的ruby,如RubyInstallerruby

 RailsInstaller and Ruby Stack

If you are installing Ruby in order to use Ruby on Rails, you can use the following installersbash

RailsInstaller  支持OS X和Windowscurl

ide

Bitnami Ruby Stack 支持OS X、Linux和Windows工具

RVM (「Ruby Version Manager」)post

RVM allows you to install and manage multiple installations of Ruby on your system. It can also manage different gemsets. It is available for OS X, Linux, or other UNIX-like operating systems.測試

Rails安裝

sudo gem install rails

額……install了半天,被牆了麼?ui

使用淘寶鏡像

gem sources --remove https://rubygems.org/
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
gem sources -l
gem install rails

個人機器上源是不帶s的,因此第一條語句爲

gem sources --remove http://rubygems.org/

Ruby和Rail版本不一致

可能因爲以前安裝過Gitlab,已經安裝了ruby 1.3,gem install rails時,提示:

activesupport requires Ruby version >= 2.2.2

此時,能夠利用Installers來安裝多個版本的ruby,我選擇的是RVM

注:按照下面安裝ruby 2.3好像改變不了ruby -v輸出的1.9……

安裝Ruby Install

官網上有多種安裝方式,不一一列舉了,本文使用的是:

wget -O ruby-install-0.6.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.6.0.tar.gz
tar -xzvf ruby-install-0.6.0.tar.gz
cd ruby-install-0.6.0/
sudo make install

最後安裝ruby 2.3

ruby-install ruby 2.3

注:命令支持路徑,若是不帶路徑則是升級ruby

安裝RVM

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable

完了以後要

source ~/.rvm/scripts/rvm

才能使用rvm,如rvm -v

rvm requirements
rvm install 2.3.0

指定版本:

rvm use 2.3.0 --default

注:個人沒有執行這條命令,ruby -v顯示2.3.

測試

裝完rvm、ruby和rails以後

rails new blog
cd blog
rails server

其中,第一個命令會執行比較長時間,最後打開http://localhost:3000便可看到效果。

沒法經過IP地址訪問,詳見Rails啓動後,沒法經過IP訪問

可能會遇到一些問題,詳見Ruby on rails安裝問題