Ruby安装
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 system
第三方工具允许你安装多个不同版本的ruby,如RubyInstaller
RailsInstaller and Ruby Stack
If you are installing Ruby in order to use Ruby on Rails, you can use the following installers
RailsInstaller 支持OS X和Windows
和
Bitnami Ruby Stack 支持OS X、Linux和Windows
RVM (“Ruby Version Manager”)
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了半天,被墙了么?
使用淘宝镜像
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安装问题