LoginSignup
11
12

More than 5 years have passed since last update.

Ruby Sinatraのインストール

Last updated at Posted at 2015-08-12

Ruby Sinatraのインストール

  • 簡易WebサーバーであるSinatraを導入します。

1 Rubygemsをインストールします。

1.1 こちらのマニュアルに従って、rubygemsをインストールしておきます。

Ruby+gems+Railsインストールガイド

2 Sinatraをインストールします。

gem update --system
gem install rdoc
gem install sinatra
gem install sinatra-contrib

2.1 bundlerを使っている場合はこちら

/root/Gemfile

source "https://rubygems.org"
gem 'sinatra'
gem 'sinatra-contrib'

を書き加えた後、Gemfileのあるディレクトリで、(通常、ホームフォルダ)

cd
bundle install --path vendor/bundle

を実行。

3 helloworldスクリプトを書きます。

※保存先はどこでも良い

myapp.rb

require 'sinatra'
require 'sinatra/reloader'
get '/' do
    "Hello world " 
end

3.1 bundlerを使っている場合

Bundler.require
get '/' do
    "Hello world " 
end

4 Webサーバーを起動します。

http://IPアドレス:12345/にアクセスすると、"Hello world"と表示されます。
※ver.1.4.0から==development環境だと、localhostからのアクセスしか受け付けないのがデフォルト==となったため、-o 0.0.0.0オプションをつけること。(0.0.0.0は全てのアドレスを指す)

bundle exec ruby myapp.rb -o 0.0.0.0 -p 12345
11
12
0

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
11
12