How to check rails environment?

Ruby on-RailsUbuntuProduction

Ruby on-Rails Problem Overview


How check rails environment on Ubuntu Server?

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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

One liner if you are in app root

> rails r "puts Rails.env"

Solution 2 - Ruby on-Rails

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?

Solution 3 - Ruby on-Rails

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

Solution 4 - Ruby on-Rails

On your Rails Application directory type :

> rake about

Solution 5 - Ruby on-Rails

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"

Solution 6 - Ruby on-Rails

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

PS 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexander ShlenchackView Question on Stackoverflow
Solution 1 - Ruby on-RailsDino ReicView Answer on Stackoverflow
Solution 2 - Ruby on-RailsDavid GraysonView Answer on Stackoverflow
Solution 3 - Ruby on-RailsRana Pratap SinghView Answer on Stackoverflow
Solution 4 - Ruby on-RailsMarcelo CampusanoView Answer on Stackoverflow
Solution 5 - Ruby on-RailsGalugaView Answer on Stackoverflow
Solution 6 - Ruby on-RailsshilovkView Answer on Stackoverflow