How to check rails environment?
Asked Answered
M

6

58

How check rails environment on Ubuntu Server?

command: Rails.env => command not found command: rails.env => command not found

Mullane answered 27/4, 2013 at 7:12 Comment(1)
Are you running this command in the rails console? irb or unix shell won't do.Napier
S
125

One liner if you are in app root

rails r "puts Rails.env"

Stronski answered 9/12, 2013 at 8:32 Comment(4)
I used rails r "puts Rails.env" successfully. Upvoted your response because it is direct and simple.Ref
Hey, it is always saying development, even though I'm running in staging.Holcombe
You have to tell the rails command what environment you're running in. So, I used a command like this: rails runner --environment=production "puts Rails.version"Longrange
This one always output development?Kaleb
A
18

It sounds like you tried to run Rails.env in a shell. That won't work because Rails.env is Ruby code, not a Unix shell command.

How are you deploying and starting your rails app on the server? The Rails environment is determined by whatever the value of the RAILS_ENV environment variable is when the server starts. You might have some configuration file somewhere that specifies it, or maybe you just start your server with a command of the form RAILS_ENV=production my_rails_server? I would need to know more details about exactly what commands you run to start the server in order to really answer this. Are you using unicorn, mongrel, Webrick, or something else?

Anaptyxis answered 27/4, 2013 at 7:18 Comment(2)
Thanks. I needed to run some rake commands with RAILS_ENV=production. Where can I set default environment?Mullane
I think you could put the following command in your .bashrc on the server: export RAILS_ENV=production. Then when you are running that command on the server you should now need to specify RAILS_ENV. Be careful though; if you type rake on the server it would probably run your tests in production mode and I am not sure if it would mess up your production database.Anaptyxis
T
14

You can check complete details about your rails app. By typing this command "rake about". Will give you brief details about which version of ruby have you installed on your machine, rails version etc. For example -

About your application's environment

Rails version ------> 4.2.6

Ruby version ------> 2.3.1-p112 (x86_64-linux)

RubyGems version ----> 2.5.1

Rack version ----> 1.6.4

JavaScript Runtime -------> Node.js (V8)

Middleware ------> Rack::Sendfile, ActionDispatch::Static,

Application root ----> /data/www/testapp

Environment ------> development

Database adapter -----> mysql2

Database schema version -----> 0

Tananarive answered 2/10, 2016 at 18:27 Comment(0)
K
13

On your Rails Application directory type :

rake about

Korrie answered 17/7, 2016 at 6:53 Comment(1)
can you once try from here #16249899Forkey
P
6
rails r -e production 'p Rails.env'
production

rails r -e production 'p Rails.env.production?'
true

rails r 'p Rails.env'
development

rails r -e development 'p Rails.env.development?'
true

rails r -e test 'p Rails.env.test?'
true

PS If rails command not found try to use path bin/:

bin/rails r 'p Rails.env'
development

PS2 If use rvm, check installed ruby versions:

rvm list

ruby-2.2.0 [ x86_64 ]
ruby-2.2.4 [ x86_64 ]
ruby-2.6.2 [ x86_64 ]
ruby-2.7.0 [ x86_64 ]
ruby-2.7.1 [ x86_64 ]
=> ruby-2.7.2 [ x86_64 ]
* ruby-2.7.3 [ x86_64 ]
ruby-3.0.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Select to version:

rvm use ruby-3.0.0

Bundle install:

bundle
Pine answered 2/8, 2021 at 18:36 Comment(0)
M
4

You can also check your environment from your Rails console in the shell. Start at the application directory path.

rails console<enter>

after you see the output from your console... (your output will most likely differ)

Running via Spring preloader in process XXXXX
Loading development environment (Rails X.x.x)
irb(main):001:0>

At the promt type

Rails.env<enter>

Unless you have custom environments, one of the following environment is loaded

=> "development"
=> "production"
=> "test"
Morehouse answered 25/3, 2018 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.