LoginSignup
15
17

More than 5 years have passed since last update.

Sinatraのインストールとsinatra-contribのエラーの回避

Last updated at Posted at 2015-04-10

前提

Vagrantで作成した仮想マシンで、Ruby他がなんとなく動いてる状態から、sinatraが使える状態までをゴールにしています。

事前準備

Vagrantで作成した仮想マシンに作業用フォルダを作成し、移動する。

Sinatraのインストール

sinatraのインストール
$ gem install sinatra

sinatra-contribのインストール
$ gem install sinatra-contrib

データベースを使う場合のインストール

Active_Recordのインストール
$ gem install activerecord

SQLite3のインストール
$ gem install sqlite3

WEBサーバの立ち上げ

ruby {hogehoge.rb} -h で起動オプションを確認する
$ ruby {hogehoge.rb} -o 192.168.33.10

ポート番号を確認する。デフォルトは、4567
$ http://192.168.33.10:4567/

Sinatraの停止、ターミナルで「Ctrl+C」

リロードの設定

{hogehoge.rb}に追記する
require 'sinatra/reloader'

WEBサーバの立ち上げ
$ ruby {hogehoge.rb} -o 192.168.33.10

エラーが出る場合

errorの内容

/home/vagrant/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:2112:in `raise_if_conflicts': Unable to activate sinatra-contrib-1.4.2, because tilt-2.0.1 conflicts with tilt (~> 1.3) (Gem::ConflictError)

衝突しているGemを取り除いてみる。
該当のGemを確認
$ gem list

tilt (2.0.1, 1.4.1)があることを確認できる。
ログを見ればわかりますが、実はsinaraインストール時にtilt2.0.1が、sinatra-contribインストール時にtilt1.4.1がインストールされてます。どちらかをアンインストールすることでエラーを回避できるはず。
$ gem uninstall tilt

選択肢が現れる
Select gem to uninstall:
 1. tilt-1.4.1
 2. tilt-2.0.1
 3. All versions

2.を選びます。

これでエラーは解消されます。tilt-2.0.1を外すことによる他への影響は不明です。

15
17
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17