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安装问题

相关文章
相关标签/搜索