0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【bin/】rails の違いについて

Last updated at Posted at 2025-02-10

rails server と bin/rails serverの違いについて

rails server と bin/rails serverの違いが気になり調べたので以下まとめておきます。

【結論】
「rails server」の方は システム全体でインストールされている rails を使用し,
「bin/rails server」の方は アプリケーション固有の Bundler 環境に基づいて実行されます。

「rails server」の方のシステム全体でインストールされているrailsに対して、コマンドを実行するとは

例えば、
同じPC内で複数のrailsアプリを作成していた場合、
それぞれのアプリでインストールしているgemが異るとして、rails serverでrailsを立ち上げると、システム全体に対してアクションを起こすため、グローバルにインストールされた gem の影響を受けやすく、そのアプリケーションで期待されるGemfileにならない可能性があります。

一方、
「bin/rails server」では、
アプリケーション固有の Bundler 環境(Gemfileで定義された依存関係)で実行されます。そのため、異なるプロジェクトやグローバル環境の gem の影響を受けにくく、プロジェクトで期待されるバージョンや設定でコマンドが実行されます。

railsの起動に失敗した場合、gemの依存関係がエラー原因であることも考えられるため、
bin/rails serverで再度起動してみるのもよいかと思いました。

【補足】
Windowsでは、「bin/rails server」で実行しても反応がなかったので、
「bundle exec rails server」で実行しました。
bundle exec を使用すると、Bundler で管理されているプロジェクト固有の gem 環境でサーバーを起動できます。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?