How check rails environment on Ubuntu Server?
command: Rails.env => command not found
command: rails.env => command not found
Use command ENV in rails console. That will return a hash of your environmental values you can access. Alternatively, you can access your environmental variables from your apps root path using the same command and the variables will be returned formatted.
When we generate a new Rails application we get three environments by default: development , test and production . There's nothing special about these particular environments, though, and there are very few places in the Rails source code that refer to them.
Ruby on Rails Configuration Environments in Rails By default rails has 3 environments, development , production and test . By editing each file you are editing the configuration for that environment only. Rails also has a configuration file in config/application.
The ENV hash in your Rails application is set when your Rails application starts. Rails loads into ENV any environment variables stored in your computer and any other key-value pairs you add using Figaro gem.
One liner if you are in app root
rails r "puts Rails.env"
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?
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
On your Rails Application directory type :
rake about
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With