Ubuntu Ruby On Rails

本文详细介绍了Ruby及Rails的安装过程,包括使用官方包管理器、第三方工具、RVM等方法,并提供了解决Ruby版本冲突的方法及如何配置国内镜像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

转载于:https://my.oschina.net/shanlilaideyu/blog/708594

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值