Getting Started on Heroku with Ruby
Introduction
Complete this tutorial to deploy a sample Ruby app to Heroku Private Spaces on the Fir generation of the platform. To deploy the app to the Common Runtime or Cedar Private Spaces, follow this guide instead.
The tutorial assumes that you have:
- A verified Heroku Account
- An existing Fir Private Space
- A team admin or member role that has the
app creation
permission on the space. - An SSH key added to your Heroku account
- Ruby 3.4.6 installed locally - see the installation guides for Ruby and Rails on macOS, Windows, and Linux
- Bundler installed locally - run
gem install bundler
- Postgres installed locally
Using dynos and databases to complete this tutorial counts towards your usage. We recommend using dyno-1c-0.5gb dynos and an Essential-0 Postgres database to complete this tutorial. Delete all resources after completing the tutorial.
Set Up
Install the Heroku Command Line Interface (CLI). Use the CLI to manage and scale your app, provision add-ons, view your logs, and run your app locally.
The Heroku CLI requires Git, the popular version control system. If you don’t already have Git installed, complete the following before proceeding:
Download and run the installer for your platform:
Download the appropriate installer for your Windows installation:
You can find more installation options for the Heroku CLI here.
After installation, you can use the heroku
command from your command shell.
To log in to the Heroku CLI, use the heroku login
command:
$ heroku login heroku: Press any key to open up the browser to login or q to exit: Opening browser to https://cli-auth.heroku.com/auth/cli/browser/*** heroku: Waiting for login... Logging in... done Logged in as me@example.com
This command opens your web browser to the Heroku login page. If your browser is already logged in to Heroku, click the Log In
button on the page.
This authentication is required for the heroku
and git
commands to work correctly.
If you have any problems installing or using the Heroku CLI, see the main Heroku CLI article for advice and troubleshooting steps.
If you’re behind a firewall that uses a proxy to connect with external HTTP/HTTPS services, set the HTTP_PROXY
or HTTPS_PROXY
environment variables in your local development environment before running the heroku
command.
Clone the Sample App
If you’re new to Heroku, it’s recommended that you complete this tutorial using the Heroku-provided sample application.
To deploy an existing application, follow this article instead.
Clone the sample application to get a local version of the code. Execute these commands in your local command shell or terminal:
$ git clone https://github.com/heroku/ruby-getting-started.git $ cd ruby-getting-started
You now have a functioning Git repository that contains a simple application. It includes a Gemfile
file, which Ruby’s dependency manager, bundler
, uses to install dependencies.
Define a Procfile
Use a Procfile, a text file in the root directory of your application, to explicitly declare what command to execute to start your app.
The Procfile
in the example app looks like this:
web: bundle exec puma -C config/puma.rb
This Procfile declares a single process type, web
, and the command needed to run it. The name web
is important here. It declares that this process type is attached to Heroku’s HTTP routing stack and receives web traffic when deployed. The command used here runs Puma, the web server, and passes in a configuration file.
A Procfile can contain additional process types. For example, you can declare a background worker process that processes items off a queue.
Configure an IPv6 Host
The code we’re deploying is already ready for IPv6, but when you’re deploying your own app you must make sure it binds to the IPv6 interface.
Fir uses IPv6 to route web requests. By default, Puma will try to bind to the IPv4 host 0.0.0.0
. Your app must instead bind to the IPv6 host ::
. To accomplish this, use Puma’s port
DSL in config/puma.rb
:
# Support IPv6 by binding to host `::` in production instead of `0.0.0.0` and `::1` instead of `127.0.0.1` in development. host = ENV.fetch("RAILS_ENV") { "development" } == "production" ? "::" : "::1" # PORT environment variable is set by Heroku in production. port(ENV.fetch("PORT") { 3000 }, host)
If you’re using rails server
or bin/rails server
in your Procfile
, you must set the host with the --binding "[::]"
flag. For example:
web: bin/rails server --binding "[::]" --port "${PORT:?Error: PORT env var is not set!}" --environment "$RAILS_ENV"
Create Your App in a Fir Space
Delete your app and database as soon as you’re done to control costs.
You can get a list of all Heroku spaces by running $ heroku spaces
Create an app on Heroku to prepare the platform to receive your source code by replacing <space-name>
with the name of your Fir space in the command below:
$ heroku create --space <space-name> Creating app in space <space name>... Creating app in space <space name>... done, warm-eyrie-94250 http://warm-eyrie-94250-b90cfafbdb4b.rose-virginia.herokuapp.com/ | https://git.heroku.com/warm-eyrie-94250.git
When you create an app, a Git remote called heroku
also gets created and associated with your local Git repository. Git remotes are versions of your repository that live on other servers. You deploy your app by pushing its code to that special Heroku-hosted remote associated with your app.
Heroku generates a random name for your app, in this case, warm-eyrie-94250
. You can specify your own app name.
Provision a Database
The sample app requires a database. Provision a Heroku Postgres database, an add-on available through the Elements Marketplace. Add-ons are cloud services that provide out-of-the-box additional services for your application, such as logging, monitoring, databases, and more.
An essential-0
Postgres size costs $5 a month, prorated to the minute. At the end of this tutorial, we prompt you to delete your database to minimize costs. For production apps in Private Spaces, you might want to use a private database plan such as private-0
or higher.
$ heroku addons:create heroku-postgresql:essential-0 --confirm warm-eyrie-94250 -- --region us Creating heroku-postgresql:essential-0 on warm-eyrie-94250... Creating heroku-postgresql:essential-0 on warm-eyrie-94250... ~$0.007/hour (max $5/month) Database should be available soon postgresql-shaped-72703 is being created in the background. The app will restart when complete... Use heroku addons:info postgresql-shaped-72703 to check creation progress Use heroku addons:docs heroku-postgresql to view documentation
You can wait for the database to provision by running this command:
$ heroku pg:wait
After that command exits, your Heroku app can access the Postgres database. The DATABASE_URL
environment variable stores your credentials, which your app is configured to connect to. You can see all the add-ons provisioned with the addons
command:
$ heroku addons Add-on Plan Price Max price State ─────────────────────────────────────────── ─────────── ──────────── ───────── ─────── heroku-postgresql (postgresql-shaped-72703) essential-0 ~$0.007/hour $5/month created └─ as DATABASE The table above shows add-ons and the attachments to the current app (warm-eyrie-94250) or other apps.
Deploy the App
Using a dyno to complete this tutorial counts towards your usage. Delete your app and database as soon as you’re done to control costs.
Deploy your code. This command pushes the main
branch of the sample repo to your heroku
remote, which then deploys to Heroku:
$ git push heroku main remote: Updated 103 paths from fc29e68 remote: Compressing source files... done. remote: Building source: remote: Heroku Labs: Build Time Config Vars are *not enabled*. remote: By default, your config vars are only available at runtime. See https://devcenter.heroku.com/build-time-config-vars for details on Build Time Config Vars. remote: Extracting source remote: Image with name "warm-eyrie-94250/builds" not found remote: 2 of 5 buildpacks participating remote: heroku/ruby 12.1.0 remote: heroku/procfile 4.2.1 remote: remote: ## Heroku Ruby Buildpack remote: remote: - Ruby version `3.4.6` from `Gemfile.lock` remote: - Installing ... (0.9s) remote: - Bundler version `2.7.2` from `Gemfile.lock` remote: - Running `gem install bundler --version 2.7.2 --install-dir /layers/heroku_ruby/bundler --bindir /layers/heroku_ruby/bundler/bin --force --no-document --env-shebang` ... (0.4s) remote: - Bundle install gems remote: - Running `BUNDLE_FROZEN="1" BUNDLE_GEMFILE="/workspace/Gemfile" BUNDLE_WITHOUT="development:test" bundle install` remote: remote: Fetching gem metadata from https://rubygems.org/......... remote: Fetching rake 13.3.0 remote: Installing rake 13.3.0 remote: Fetching base64 0.3.0 remote: Fetching benchmark 0.4.1 remote: Fetching bigdecimal 3.2.3 remote: Fetching concurrent-ruby 1.3.5 remote: Installing base64 0.3.0 remote: Installing benchmark 0.4.1 remote: Installing bigdecimal 3.2.3 with native extensions remote: Fetching connection_pool 2.5.4 remote: Installing connection_pool 2.5.4 remote: Fetching drb 2.2.3 remote: Installing drb 2.2.3 remote: Fetching logger 1.7.0 remote: Fetching minitest 5.25.5 remote: Installing concurrent-ruby 1.3.5 remote: Installing logger 1.7.0 remote: Installing minitest 5.25.5 remote: Fetching securerandom 0.4.1 remote: Installing securerandom 0.4.1 remote: Fetching uri 1.0.3 remote: Fetching builder 3.3.0 remote: Installing uri 1.0.3 remote: Installing builder 3.3.0 remote: Fetching erubi 1.13.1 remote: Fetching racc 1.8.1 remote: Installing erubi 1.13.1 remote: Installing racc 1.8.1 with native extensions remote: Fetching crass 1.0.6 remote: Installing crass 1.0.6 remote: Fetching rack 3.2.1 remote: Installing rack 3.2.1 remote: Fetching useragent 0.16.11 remote: Installing useragent 0.16.11 remote: Fetching nio4r 2.7.4 remote: Installing nio4r 2.7.4 with native extensions remote: Fetching websocket-extensions 0.1.5 remote: Installing websocket-extensions 0.1.5 remote: Fetching zeitwerk 2.7.3 remote: Installing zeitwerk 2.7.3 remote: Fetching timeout 0.4.3 remote: Installing timeout 0.4.3 remote: Fetching marcel 1.1.0 remote: Installing marcel 1.1.0 remote: Fetching mini_mime 1.1.5 remote: Installing mini_mime 1.1.5 remote: Fetching date 3.4.1 remote: Installing date 3.4.1 with native extensions remote: Fetching msgpack 1.8.0 remote: Installing msgpack 1.8.0 with native extensions remote: Fetching erb 5.0.2 remote: Installing erb 5.0.2 with native extensions remote: Fetching ffi 1.17.2 (aarch64-linux-gnu) remote: Installing ffi 1.17.2 (aarch64-linux-gnu) remote: Fetching prettyprint 0.2.0 remote: Installing prettyprint 0.2.0 remote: Fetching stringio 3.1.7 remote: Installing stringio 3.1.7 with native extensions remote: Fetching io-console 0.8.1 remote: Installing io-console 0.8.1 with native extensions remote: Fetching thor 1.4.0 remote: Installing thor 1.4.0 remote: Fetching tsort 0.2.0 remote: Installing tsort 0.2.0 remote: Fetching rb-fsevent 0.11.2 remote: Installing rb-fsevent 0.11.2 remote: Fetching pg 1.6.2 (aarch64-linux) remote: Installing pg 1.6.2 (aarch64-linux) remote: Fetching rack-timeout 0.7.0 remote: Installing rack-timeout 0.7.0 remote: Fetching i18n 1.14.7 remote: Installing i18n 1.14.7 remote: Fetching tzinfo 2.0.6 remote: Installing tzinfo 2.0.6 remote: Fetching rack-session 2.1.1 remote: Installing rack-session 2.1.1 remote: Fetching rack-test 2.2.0 remote: Installing rack-test 2.2.0 remote: Fetching rackup 2.2.1 remote: Installing rackup 2.2.1 remote: Fetching websocket-driver 0.8.0 remote: Installing websocket-driver 0.8.0 with native extensions remote: Fetching net-protocol 0.2.2 remote: Installing net-protocol 0.2.2 remote: Fetching nokogiri 1.18.10 (aarch64-linux-gnu) remote: Fetching puma 7.0.4 remote: Installing puma 7.0.4 with native extensions remote: Installing nokogiri 1.18.10 (aarch64-linux-gnu) remote: Fetching rb-inotify 0.11.1 remote: Installing rb-inotify 0.11.1 remote: Fetching pp 0.6.2 remote: Installing pp 0.6.2 remote: Fetching bootsnap 1.18.6 remote: Installing bootsnap 1.18.6 with native extensions remote: Fetching activesupport 8.0.3 remote: Installing activesupport 8.0.3 remote: Fetching net-pop 0.1.2 remote: Installing net-pop 0.1.2 remote: Fetching net-smtp 0.5.1 remote: Installing net-smtp 0.5.1 remote: Fetching loofah 2.24.1 remote: Installing loofah 2.24.1 remote: Fetching listen 3.9.0 remote: Installing listen 3.9.0 remote: Fetching rails-dom-testing 2.3.0 remote: Installing rails-dom-testing 2.3.0 remote: Fetching globalid 1.3.0 remote: Installing globalid 1.3.0 remote: Fetching activemodel 8.0.3 remote: Installing activemodel 8.0.3 remote: Fetching rails-html-sanitizer 1.6.2 remote: Installing rails-html-sanitizer 1.6.2 remote: Fetching activejob 8.0.3 remote: Installing activejob 8.0.3 remote: Fetching activerecord 8.0.3 remote: Installing activerecord 8.0.3 remote: Fetching actionview 8.0.3 remote: Installing actionview 8.0.3 remote: Fetching actionpack 8.0.3 remote: Installing actionpack 8.0.3 remote: Fetching actioncable 8.0.3 remote: Installing actioncable 8.0.3 remote: Fetching activestorage 8.0.3 remote: Installing activestorage 8.0.3 remote: Fetching propshaft 1.3.1 remote: Installing propshaft 1.3.1 remote: Fetching actiontext 8.0.3 remote: Installing actiontext 8.0.3 remote: Fetching reline 0.6.2 remote: Installing reline 0.6.2 remote: Fetching net-imap 0.5.11 remote: Fetching psych 5.2.6 remote: Installing net-imap 0.5.11 remote: Installing psych 5.2.6 with native extensions remote: Fetching mail 2.8.1 remote: Installing mail 2.8.1 remote: Fetching actionmailbox 8.0.3 remote: Fetching actionmailer 8.0.3 remote: Installing actionmailbox 8.0.3 remote: Installing actionmailer 8.0.3 remote: Fetching rdoc 6.14.2 remote: Installing rdoc 6.14.2 remote: Fetching irb 1.15.2 remote: Fetching sdoc 2.6.4 remote: Installing irb 1.15.2 remote: Installing sdoc 2.6.4 remote: Fetching railties 8.0.3 remote: Installing railties 8.0.3 remote: Fetching importmap-rails 2.2.2 remote: Fetching rails 8.0.3 remote: Installing importmap-rails 2.2.2 remote: Installing rails 8.0.3 remote: Bundle complete! 10 Gemfile dependencies, 77 gems now installed. remote: Gems in the groups 'development' and 'test' were not installed. remote: Use `bundle info [gemname]` to see where a bundled gem is installed. remote: remote: - Done (18.0s) remote: - Running `bundle clean --force` ... (0.3s) remote: - Default process detection remote: - Running `bundle list` ... (0.2s) remote: - Detected rails app (`rails` gem found) remote: - Rake assets install remote: - Detected rake (`rake` gem found, `Rakefile` found at `/workspace/Rakefile`) remote: - Running `rake -P --trace` ..... (2.3s) remote: - Compiling assets with cache (detected `rake assets:precompile` and `rake assets:clean` via `rake -P`) remote: - Creating cache for /workspace/public/assets remote: - Creating cache for /workspace/tmp/cache/assets remote: - Running `rake assets:precompile assets:clean --trace` remote: remote: ** Invoke assets:precompile (first_time) remote: ** Invoke environment (first_time) remote: ** Execute environment remote: ** Execute assets:precompile remote: ** Invoke assets:clean (first_time) remote: ** Invoke environment remote: ** Execute assets:clean remote: Writing lang-logo-27c62977.png remote: Writing application-f5e7b2f6.css remote: Writing actiontext.esm-f1c04d34.js remote: Writing actiontext-a4ee937e.js remote: Writing trix-4b540cb5.js remote: Writing trix-65afdb1d.css remote: Writing action_cable-5212cfee.js remote: Writing actioncable.esm-e0ec9819.js remote: Writing actioncable-ac25813f.js remote: Writing activestorage.esm-f2909226.js remote: Writing activestorage-32201f68.js remote: Writing rails-ujs.esm-e925103b.js remote: Writing rails-ujs-20eaf715.js remote: remote: - Done (1.0s) remote: - Storing cache for /workspace/public/assets remote: - Storing cache for (empty) /workspace/tmp/cache/assets remote: - Done (finished in 23.5s) remote: remote: ## Procfile Buildpack remote: remote: - Processes from `Procfile` remote: - web: `bundle exec puma -C config/puma.rb` remote: - Done (finished in < 0.1s) remote: Adding layer 'heroku/ruby:binruby' remote: Adding layer 'heroku/ruby:bundler' remote: Adding layer 'heroku/ruby:cache_public_assets' remote: Adding layer 'heroku/ruby:cache_tmp_cache_assets' remote: Adding layer 'heroku/ruby:env_defaults' remote: Adding layer 'heroku/ruby:gems' remote: Adding layer 'heroku/ruby:user_binstubs' remote: Adding layer 'buildpacksio/lifecycle:launch.sbom' remote: Added 1/1 app layer(s) remote: Adding layer 'buildpacksio/lifecycle:launcher' remote: Adding layer 'buildpacksio/lifecycle:config' remote: Adding layer 'buildpacksio/lifecycle:process-types' remote: Adding label 'io.buildpacks.lifecycle.metadata' remote: Adding label 'io.buildpacks.build.metadata' remote: Adding label 'io.buildpacks.project.metadata' remote: Setting default process type 'web' remote: Saving warm-eyrie-94250/builds... remote: *** Images (sha256:30a04a41fce0239d2679091bebda6336230ea3f16c830f356ba811389a4fb73b): remote: warm-eyrie-94250/builds:9a570c30-8a63-4a31-92d1-f7d83368bb7d remote: Adding cache layer 'heroku/ruby:binruby' remote: Adding cache layer 'heroku/ruby:bundler' remote: Adding cache layer 'heroku/ruby:cache_public_assets' remote: Adding cache layer 'heroku/ruby:cache_tmp_cache_assets' remote: Adding cache layer 'heroku/ruby:gems' remote: Uploading cache remote: Launching... remote: https://warm-eyrie-94250-b90cfafbdb4b.rose-virginia.herokuapp.com/ deployed to Heroku remote: Verifying deploy... done. To https://git.heroku.com/warm-eyrie-94250.git * [new branch] main -> main
The app is now deployed. The default dyno size for Fir Private Spaces is dyno-1c-0.5gb.
Visit the app at the URL shown in the logs. As a shortcut, you can also open the website as follows:
$ heroku open
View Logs
Fir apps do not retain log history like Cedar apps. To view an event in your Fir logs, you must run the logging command while that event occurs.
Heroku treats logs as streams of time-ordered events, aggregated from the output streams of all your app and Heroku components. Heroku provides a single stream for all events. View information about your running app by using one of the logging commands:
$ heroku logs Fetching logs... 2025-10-07T21:17:11.558106+00:00 heroku-runtime[logs]: Log stream started. Waiting for logs... 2025-10-07T21:17:13.572181+00:00 app[web-6c55b54cc5-l9l8r]: source=rack-timeout id=63f8ab98-1032-eb01-c2ac-467e5f4c425d wait=2ms timeout=15000ms state=ready 2025-10-07T21:17:13.573150+00:00 app[web-6c55b54cc5-l9l8r]: [63f8ab98-1032-eb01-c2ac-467e5f4c425d] Started GET "/" for 66.203.115.15 at 2025-10-07 21:17:13 +0000 2025-10-07T21:17:13.577953+00:00 app[web-6c55b54cc5-l9l8r]: [63f8ab98-1032-eb01-c2ac-467e5f4c425d] Processing by WelcomeController#index as */* 2025-10-07T21:17:13.592957+00:00 app[web-6c55b54cc5-l9l8r]: [63f8ab98-1032-eb01-c2ac-467e5f4c425d] Rendered layout layouts/application.html.erb (Duration: 1.8ms | GC: 0.0ms) 2025-10-07T21:17:13.595000+00:00 app[web-6c55b54cc5-l9l8r]: [63f8ab98-1032-eb01-c2ac-467e5f4c425d] Completed 200 OK in 15ms (Views: 14.2ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 11.0ms) 2025-10-07T21:17:13.596734+00:00 app[web-6c55b54cc5-l9l8r]: [63f8ab98-1032-eb01-c2ac-467e5f4c425d] source=rack-timeout id=63f8ab98-1032-eb01-c2ac-467e5f4c425d wait=2ms timeout=15000ms service=25ms state=completed 2025-10-07T21:17:13.598047+00:00 heroku-router[web]: at=info method=GET path="/" host=warm-eyrie-94250-b90cfafbdb4b.rose-virginia.herokuapp.com request_id=63f8ab98-1032-eb01-c2ac-467e5f4c425d fwd="123.456.789.0" dyno=web-6c55b54cc5-l9l8r connect=0ms service=27ms status=200 bytes=9031 protocol=http tls_version=tls1.3
To generate more log messages, refresh the app in your browser.
To stop streaming the logs, press Ctrl
+C
.
Declare App Dependencies
Heroku recognizes an app as a Ruby app by the existence of a Gemfile
file in the root directory.
The demo app you deployed already has a Gemfile
:
source 'https://rubygems.org' ruby '>= 3.1', '< 3.5' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 8.0.3" # The modern asset pipeline for Rails [https://github.com/rails/propshaft] gem "propshaft" # Use postgresql as the database for Active Record gem 'pg', '~> 1.6.1' # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] gem "importmap-rails" ...
The Gemfile
file specifies the dependencies to install with your application. It also determines the version of Ruby used to run your application on Heroku.
When an app deploys, Heroku reads this file and installs the appropriate Ruby version and dependencies using the bundle install
command.
To run the app locally, you must also install dependencies locally. This Gemfile dependency pg
only resolves if you have Postgres installed locally. Install Postgres before you proceed.
If the command which psql
returns some value on your command line, you have Postgres installed locally:
$ which psql /usr/local/bin/psql
Run bundle install
in your local directory to install the dependencies, preparing your system for running the app locally:
$ bundle install Bundle complete! 10 Gemfile dependencies, 79 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed.
After installing dependencies, you can run your app locally.
Run the App Locally
The sample app uses a database, so you must create the database and table locally using the rake
task:
$ bundle exec rake db:create db:migrate Source locally installed gems is ignoring #<Bundler::StubSpecification name=sassc version=2.4.0 platform=ruby> because it is missing extensions Source locally installed gems is ignoring #<Bundler::StubSpecification name=racc version=1.8.1 platform=ruby> because it is missing extensions Created database 'ruby-getting-started_development' Created database 'ruby-getting-started_test'
Now start your application locally using the heroku local
command:
$ heroku local web --port=5006 [OKAY] Loaded ENV .env File as KEY=VALUE Format 4:17:20 PM web.1 | Source locally installed gems is ignoring #<Bundler::StubSpecification name=sassc version=2.4.0 platform=ruby> because it is missing extensions 4:17:20 PM web.1 | Source locally installed gems is ignoring #<Bundler::StubSpecification name=racc version=1.8.1 platform=ruby> because it is missing extensions 4:17:20 PM web.1 | [34599] Puma starting in cluster mode... 4:17:20 PM web.1 | [34599] * Puma version: 7.0.4 ("Romantic Warrior") 4:17:20 PM web.1 | [34599] * Ruby version: ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [arm64-darwin24] 4:17:20 PM web.1 | [34599] * Min threads: 3 4:17:20 PM web.1 | [34599] * Max threads: 3 4:17:20 PM web.1 | [34599] * Environment: development 4:17:20 PM web.1 | [34599] * Master PID: 34599 4:17:20 PM web.1 | [34599] * Workers: 2 4:17:20 PM web.1 | [34599] * Restarts: (✔) hot (✖) phased (✖) refork 4:17:20 PM web.1 | [34599] * Preloading application 4:17:20 PM web.1 | [34599] * Listening on http://[::1]:5006 4:17:20 PM web.1 | [34599] Use Ctrl-C to stop 4:17:20 PM web.1 | [34599] - Worker 0 (PID: 34613) booted in 0.0s, phase: 0
Just like Heroku, heroku local
uses the Procfile
to know what command to execute.
To see your app running locally,open http://localhost:5006 with your web browser.
To stop the app from running locally, in the CLI, press Control + C
to exit.
Push Local Changes
In this step, you propagate a local change to the application to Heroku.
Modify Gemfile
to include an additional dependency for the cowsay
gem.
In file Gemfile
, on line 4 add:
gem "cowsay"
The file now looks like this:
source 'https://rubygems.org' ruby '>= 3.1', '< 3.5' gem "cowsay" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" ...
Modify app/views/welcome/index.erb
to use the cowsay gem.
At the end of app/views/welcome/index.erb
add:
<pre><%= Cowsay.say("Hello", "tux") %></pre>
Now test locally:
$ bundle install $ heroku local --port=5006
Visit your application at http://localhost:5006. If your changes worked, you see a cute ASCII picture displayed.
Now deploy this local change to Heroku.
Almost every deploy to Heroku follows this same pattern. First, add the modified files to the local Git repository:
$ git add .
Now commit the changes to the repository:
$ git commit -m "Added cowsay gem" [main e5e0a5a] Added cowsay gem 5 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 install.txt
Now deploy as before:
$ git push heroku main
Finally, check that everything is working:
$ heroku open
Debugging
The Heroku Ruby Cloud Native Buildpack (CNB) turns your code into an Open Container Initiative (OCI) container image when you deploy to Fir. This image gets executed on our dynos.
You can use this image locally to reproduce and debug deployment problems. Build an OCI image from your application to debug locally by using the Heroku Ruby CNB. If you’re interested, check out the Ruby CNB tutorial.
Start a Console
The heroku run
command to launch an interactive one-off dyno is unavailable for Fir. As an alternative, use heroku run:inside
to access a running dyno until we add heroku run
for Fir.
You must add an SSH key to your Heroku account before running this command.
To execute the command you need the name of a currently running process. You can see a list with heroku ps
:
$ heroku ps === web (dyno-1c-0.5gb): bundle exec puma -C config/puma.rb (1) web-6c55b54cc5-l9l8r: up 2025/10/07 16:16:57 -0500 (~ 26s ago)
Use that dyno name to run an interactive bash
session:
$ heroku run:inside web-6c55b54cc5-l9l8r "bash" Running launcher bash on warm-eyrie-94250... Running launcher bash on warm-eyrie-94250... up, web-6c55b54cc5-l9l8r heroku@web-6c55b54cc5-l9l8r:/workspace$ ruby -v ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [aarch64-linux] heroku@web-6c55b54cc5-l9l8r:/workspace$ rails -v Rails 8.0.3 heroku@web-6c55b54cc5-l9l8r:/workspace$ ls -lah total 56K drwxrwxrwx. 1 heroku heroku 17 Jan 1 1980 . drwxr-xr-x. 1 root root 34 Oct 7 21:16 .. -rw-r--r--. 1 heroku heroku 9 Jan 1 1980 .env drwxr-xr-x. 2 heroku heroku 46 Jan 1 1980 .github -rw-r--r--. 1 heroku heroku 567 Jan 1 1980 .gitignore -rw-r--r--. 1 heroku heroku 1.1K Jan 1 1980 Gemfile -rw-r--r--. 1 heroku heroku 5.5K Jan 1 1980 Gemfile.lock -rw-r--r--. 1 heroku heroku 40 Jan 1 1980 Procfile -rw-r--r--. 1 heroku heroku 3.0K Jan 1 1980 README.md -rw-r--r--. 1 heroku heroku 249 Jan 1 1980 Rakefile drwxr-xr-x. 8 heroku heroku 96 Jan 1 1980 app -rw-r--r--. 1 heroku heroku 281 Jan 1 1980 app.json drwxr-xr-x. 2 heroku heroku 115 Jan 1 1980 bin drwxr-xr-x. 5 heroku heroku 16K Jan 1 1980 config -rw-r--r--. 1 heroku heroku 154 Jan 1 1980 config.ru drwxr-xr-x. 3 heroku heroku 54 Jan 1 1980 db drwxr-xr-x. 4 heroku heroku 33 Jan 1 1980 lib drwxr-xr-x. 2 heroku heroku 19 Jan 1 1980 log drwxr-xr-x. 3 heroku heroku 189 Jan 1 1980 public drwxr-xr-x. 8 heroku heroku 126 Jan 1 1980 test drwxr-xr-x. 1 heroku heroku 38 Oct 7 21:16 tmp drwxr-xr-x. 3 heroku heroku 20 Jan 1 1980 vendor heroku@web-6c55b54cc5-l9l8r:/workspace$ exit exit
If you receive an error, Error connecting to process
, configure your firewall.
Type exit
to exit the shell. You can run any command this way such as rails console
or rake db:migrate
.
Define Config Vars
Heroku lets you externalize configuration by storing data such as encryption keys or external resource addresses in config vars.
At runtime, we expose config vars as environment variables to the application.
Config vars for Fir-generation apps are only available at runtime by default. You can enable Build Time Config Vars to allow for both build and runtime availability.
For example, modify app/views/welcome/index.erb
so that the method repeats an action depending on the value of the TIMES
environment variable. Change the file so that its first few lines read as follows:
<% for i in 0..(ENV['TIMES'] ? ENV['TIMES'].to_i : 2) do %> <p>Hello World #<%= i %>!</p> <% end %>
The heroku local
command automatically sets up the environment based on the contents of the .env
file in your local directory. In the top level directory of your sample project, there’s already a .env
file that contains:
TIMES=10
If you run the app with heroku local --port=5006
, you see “Hello World” ten times when you refresh your browser.
To set the config var on Heroku, execute the following:
$ heroku config:set TIMES=10 Setting TIMES and restarting warm-eyrie-94250... Setting TIMES and restarting warm-eyrie-94250... done, v5 TIMES: 10
View the app’s config vars using heroku config
:
$ heroku config TIMES: 10 ...
To see this change in action, deploy your changed application to Heroku.
Use a Database
Listing the config vars for your app displays the URL that your app uses to connect to the database, DATABASE_URL
:
$ heroku config DATABASE_URL: postgres://xx:yyy@host:5432/d8slm9t7b5mjnd HEROKU_POSTGRESQL_BROWN_URL: postgres://xx:yyy@host:5432/d8slm9t7b5mjnd ...
Heroku also provides a pg
command that shows a lot more information:
$ heroku pg === DATABASE_URL Plan: essential-0 Status: Available Connections: unknown/20 PG Version: 17.4 Created: 2025-10-07 21:12 Data Size: unknown usage / 1 GB (In compliance) Tables: 0/4000 (In compliance) Fork/Follow: Unsupported Rollback: Unsupported Continuous Protection: Off Add-on: postgresql-shaped-72703
The example app you deployed already has database functionality. It has a controller and database model for widgets, used by your app’s /widgets
page. You can visit the page by appending /widgets
to your app’s URL.
If you visit the URL, you see an error page appear. Check out the error message using heroku logs
or in Papertrail to see something like this:
PG::UndefinedTable: ERROR: relation "widgets" does not exist
This error indicates that while we could connect to the database, the widgets
table wasn’t found. You can fix that error by running rake db:migrate
via run:inside
. To execute this command on Heroku, run it inside an existing dyno like so:
$ heroku run:inside web-6776df5f5-pkzh7 "rake db:migrate db:migrate:status" Running launcher rake db:migrate db:migrate:status on warm-eyrie-94250... Running launcher rake db:migrate db:migrate:status on warm-eyrie-94250... up, web-6776df5f5-pkzh7 database: dio2kovvn716o Status Migration ID Migration Name --------------------------------------------------
Now if you visit the /widgets
page of your app again, you can list and create widget records.
If you have Postgres installed locally, you can also interact directly with the database. For example, here’s how to connect to the database using psql
and execute a query:
$ heroku pg:psql d8slm9t7b5mjnd=> \x d8slm9t7b5mjnd=> select * from widgets; -[ RECORD 1 ]--------------------------- id | 1 name | My Widget description | It's amazing stock | 100 ...
Read more about Heroku PostgreSQL.
Delete Your App
Remove the app from your account. We only charge you for the resources you used.
This action permanently deletes your application and any add-ons attached to it.
$ heroku apps:destroy
You can confirm that your app is gone with this command:
$ heroku apps --all
Next Steps
You now know how to configure and deploy a Ruby app, view logs, and start a console.
To learn more, see: