Guide
Running a Rails Server in RubyMine with Custom Environment Variables and a Specific Port
Create a Rails Server run configuration in RubyMine to set a custom port and environment variables, then verify the server starts with the expected settings.
Published by Tasadduq Burney
05 Oct 2025, 23:01 UTC
2 min37K views0

Quick answer
In RubyMine you can start a Rails server directly from the IDE by creating a Rails Server run configuration, choosing the Ruby SDK, setting the port, and adding any environment variables you need.
Step‑by‑step configuration
- Open Run → Edit Configurations….
- Click the
+button and select Rails Server. - In the configuration form:
- Set SDK to the Ruby interpreter used by your Gemfile (e.g.,
Ruby 3.2.2 (rvm)). - Enter the desired port in the Port field (e.g.,
3001). - Switch to the Environment variables tab and add pairs such as
RAILS_ENV=stagingandAPI_KEY=abc123. - Click Apply then OK.
- Press Run (the green triangle) next to the configuration name. The server output appears in the Run tool window.
How it works
RubyMine creates a temporary launch script that invokes rails server with the selected SDK, passes the -p flag for the port, and injects the supplied environment variables into the process before it starts. The IDE then attaches to the process so you can view logs and set breakpoints.
Limitations and common pitfalls
- The Rails Server template only appears if RubyMine detects a Rails facet (a
Gemfilecontaininggem 'rails'and the project marked as Ruby). If the facet is missing, add it via Settings → Languages & Frameworks → Ruby SDK and Gems → + → Rails. - RubyMine does not automatically read
.envfiles. You must either duplicate those variables in the configuration or install the EnvFile plugin to load them. - Using a port already occupied by another process yields an “Address already in use” error in the Run window. Change the port or stop the conflicting process.
- Selecting an SDK that does not match the Gemfile’s Ruby version can cause load‑path errors such as
cannot load such file -- bundler. Verify the SDK path matches the one shown bywhich rubyin your terminal.
Verifying the setup
- After starting the server, look for a line like
=> Rails 7.0.8 application starting in staging on http://0.0.0.0:3001in the Run tool window. - To confirm an environment variable was received, add a temporary initializer (
config/initializers/env_check.rb) withputs "HELLO=#{ENV['HELLO']}"and restart the server; the message should appear in the log. - Stop the server with the red square button in the Run window; the process ends and the window returns to the idle state.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.