How check rails environment on Ubuntu Server?
command: Rails.env => command not found
command: rails.env => command not found
How check rails environment on Ubuntu Server?
command: Rails.env => command not found
command: rails.env => command not found
One liner if you are in app root
rails r "puts Rails.env"
rails r "puts Rails.env"
successfully. Upvoted your response because it is direct and simple. –
Ref development
? –
Kaleb 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?
.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 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
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"
© 2022 - 2024 — McMap. All rights reserved.