How to access rails console in 2024?

Hey there! I’m somewhat new to rails, and new to Fly. I’m running a basic rails app using the information on Sign In · Fly. Nothing fancy. I need to access the rails console to create an admin user on my app, and I’m not finding anything online or in the community archives that’s getting me successfully into the rails console.

$ flyctl ssh console
Connects to server

$ bin/rails console (based off fly.toml file)
Gives me:

/usr/local/bundle/ruby/3.0.0/gems/execjs-2.9.1/lib/execjs/runtimes.rb:68:in `autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
	from /usr/local/bundle/ruby/3.0.0/gems/execjs-2.9.1/lib/execjs.rb:5:in `<module:ExecJS>'
	from /usr/local/bundle/ruby/3.0.0/gems/execjs-2.9.1/lib/execjs.rb:4:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/autoprefixer-rails-10.4.16.0/lib/autoprefixer-rails/processor.rb:4:in `<main>'
	from /usr/local/bundle/ruby/3.0.0/gems/autoprefixer-rails-10.4.16.0/lib/autoprefixer-rails.rb:39:in `require_relative'
	from /usr/local/bundle/ruby/3.0.0/gems/autoprefixer-rails-10.4.16.0/lib/autoprefixer-rails.rb:39:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/solidus_backend-4.2.3/lib/spree/backend.rb:10:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/solidus_backend-4.2.3/lib/spree_backend.rb:3:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/solidus_backend-4.2.3/lib/solidus_backend.rb:3:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/solidus-4.2.3/lib/solidus.rb:5:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
	from /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/runtime.rb:55:in `each'
	from /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/runtime.rb:55:in `block in require'
	from /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/runtime.rb:44:in `each'
	from /usr/local/bundle/gems/bundler-2.5.4/lib/bundler/runtime.rb:44:in `require'
	from /usr/local/bundle/gems/bundler-2.5.4/lib/bundler.rb:187:in `require'
	from /rails/config/application.rb:7:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/railties-7.0.8/lib/rails/command/actions.rb:22:in `require_application!'
	from /usr/local/bundle/ruby/3.0.0/gems/railties-7.0.8/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
	from /usr/local/bundle/ruby/3.0.0/gems/railties-7.0.8/lib/rails/commands/console/console_command.rb:105:in `perform'
	from /usr/local/bundle/ruby/3.0.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
	from /usr/local/bundle/ruby/3.0.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
	from /usr/local/bundle/ruby/3.0.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
	from /usr/local/bundle/ruby/3.0.0/gems/railties-7.0.8/lib/rails/command/base.rb:87:in `perform'
	from /usr/local/bundle/ruby/3.0.0/gems/railties-7.0.8/lib/rails/command.rb:48:in `invoke'
	from /usr/local/bundle/ruby/3.0.0/gems/railties-7.0.8/lib/rails/commands.rb:18:in `<main>'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:/usr/local/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /usr/local/bundle/ruby/3.0.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from bin/rails:4:in `<main>'

Not sure where to go from here!

Running fly console should work.

The specific error you are getting is that node is not in your path. Somewhere in your Dockerfile you likely have a like that looks like:

You may need to run that command yourself if you come in via fly ssh console.

I ran:

$ flyctl ssh console
$ fly console

That gives me:

-bash: fly: command not found

Then I attempted to run:

$ ENV PATH=/usr/local/node/bin:$PATH

But that gave me a similar error:

-bash: ENV: command not found

This tells me there’s something basic that I’m doing wrong. I did confirm that I have that exact line in my Dockerfile.

Sorry. Try fly console instead of fly ssh console.

That worked! flyctl ssh console gives me the command line, but fly console gives me the rails console. Probably obvious now but wasn’t at first.

From How To to Questions / Help