0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Ruby】.rbファイルの実行方法

Posted at

記事概要

拡張子.rbのファイルを使用する方法をまとめる。

前提

  • SinatraをPCにインストールしている
  • PumaをPCにインストールしている

手順

  1. Sinatraを[アプリ名].rbに読み込むため、.rbファイルに下記を記述する
    require 'sinatra'
    
  2. Rubyファイルを実行するため、ターミナルで下記を実行する
    ruby [アプリ名].rb
    
  3. 下記どちらかが表示されると、サーバーが起動している
    • パターン1
      [2020-06-16 10:51:05] INFO  WEBrick 1.4.2
      [2020-06-16 10:51:05] INFO  ruby 2.6.5 (2019-10-01) [x86_64-darwin19]
      == Sinatra (v2.0.8.1) has taken the stage on 4567 for development with backup from WEBrick
      [2020-06-16 10:51:05] INFO  WEBrick::HTTPServer#start: pid=10046 port=4567
      
    • パターン2
      == Sinatra (v2.0.8.1) has taken the stage on 4567 for development with backup from Puma
      
    • 上記が表示されず、gem install rackupが表示された場合は下記を実行し、再度Rubyを起動する
      # 下記コマンドの実行
      % gem install rackup
      
      # ynの選択が必要となるので、"y"と入力
      Overwrite the executable? [yN]
      
  4. control + Cで、サーバーを閉じる
    • サーバーを開いている間は、ターミナル.appにログが記述される
    • サーバーを閉じると、サーバー内のWebアプリケーションにアクセスできない

備考

  • SinatraとPumaのインストール方法は、こちらを参照
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?