# Rails very newbie question - setting the rails working mode

**URL:** <https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175>\
**Category:** Rails\
**Created:** [December 14, 2009, 4:03am UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175 "2009-12-14T04:03:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 4:03am UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/1 "2009-12-14T04:03:53Z")

</div>

Hi all,

I am just starting with Ruby on Rails. I bought “The Rails Way” by  
Obie F. and just finished reading the first chapter, but there’s  
something I didn’t quite understand: how so set the desired mode  
(RAILS\_ENV). The author says that it can be set in environment.rb by  
uncommenting

ENV['RAILS\_ENV"=‘production’]

but seems to discourage setting it here. Maybe I didn’t understand  
what I read correctly, but is there an alternate, more reccomendable way  
of setting the mode for a RoR app, or is this line the solution? Thanks  
for any info.

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 6:31am UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/2 "2009-12-14T06:31:43Z")

</div>

Hi Omar C.

> how so set the desired mode  
> (RAILS\_ENV). The author says that it can be set in environment.rb by  
> uncommenting
> 
> ENV['RAILS\_ENV"=‘production’]

```
A rails application can be configured to use 3 environemnts in 

```

normal case and additionally we can set more. They are Development,Test  
and Production. As the name implies your development happens in env  
development ,etc… Please check the development.rb ,test.rb and  
production.rb in config/environments. In each of them we can set the  
things needed for the corresponding environmnet. Open  
config/environment.rb Here you can set the database connectivity  
details.Each environment(development,test,production) can be connected  
to corresonding db at run time. For example to start your application  
say ‘your\_app’ in test mode (with your\_app\_test db defined in  
environment.rb) do

./script/server RAILS\_ENV=test

```
   For more information read this page

```

> **[Getting Started with Rails — Ruby on Rails Guides](https://guides.rubyonrails.org/getting_started.html)**
>
> Getting Started with RailsThis guide covers getting up and running with Ruby on Rails.After reading this guide, you will know: How to install Rails, create a new Rails application, and connect your application to a database. The general layout of a...

Sijo

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/3 "2009-12-14T17:13:45Z")

</div>

Marnen Laibow-Koser wrote:

> Ideally, you’re supposed to set the Rails environment from outside the  
> app, using the environment variable RAILS\_ENV.

What happens if you’re running more than one rails app on a machine? How  
do you handle that?

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 3:43pm UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/4 "2009-12-14T15:43:29Z")

</div>

Omar C. wrote:

> Hi all,
> 
> I am just starting with Ruby on Rails. I bought “The Rails Way” by  
> Obie F. and just finished reading the first chapter, but there’s  
> something I didn’t quite understand: how so set the desired mode  
> (RAILS\_ENV). The author says that it can be set in environment.rb by  
> uncommenting
> 
> ENV['RAILS\_ENV"=‘production’]
> 
> but seems to discourage setting it here. Maybe I didn’t understand  
> what I read correctly, but is there an alternate, more reccomendable way  
> of setting the mode for a RoR app, or is this line the solution? Thanks  
> for any info.

Ideally, you’re supposed to set the Rails environment from outside the  
app, using the environment variable RAILS\_ENV.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/5 "2009-12-14T17:57:20Z")

</div>

Marnen Laibow-Koser wrote:

> Aldric G. wrote:
> 
> > Marnen Laibow-Koser wrote:
> > 
> > > Ideally, you’re supposed to set the Rails environment from outside the  
> > > app, using the environment variable RAILS\_ENV.
> > 
> > What happens if you’re running more than one rails app on a machine? How  
> > do you handle that?
> 
> Environment variables can be separate for each process.

So you mean:  
ENV\_RAILS=“production” script/server  
ACCEPT\_KEYWORDS="~x86" emerge gcc

… That kind of thing? Or is there another way?

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 5:50pm UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/6 "2009-12-14T17:50:49Z")

</div>

Aldric G. wrote:

> Marnen Laibow-Koser wrote:
> 
> > Ideally, you’re supposed to set the Rails environment from outside the  
> > app, using the environment variable RAILS\_ENV.
> 
> What happens if you’re running more than one rails app on a machine? How  
> do you handle that?

Environment variables can be separate for each process.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 6:37pm UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/7 "2009-12-14T18:37:48Z")

</div>

Aldric G. wrote:

> Marnen Laibow-Koser wrote:
> 
> > Aldric G. wrote:
> > 
> > > Marnen Laibow-Koser wrote:
> > > 
> > > > Ideally, you’re supposed to set the Rails environment from outside the  
> > > > app, using the environment variable RAILS\_ENV.
> > > 
> > > What happens if you’re running more than one rails app on a machine? How  
> > > do you handle that?
> > 
> > Environment variables can be separate for each process.
> 
> So you mean:  
> ENV\_RAILS=“production” script/server  
> ACCEPT\_KEYWORDS=“~x86” emerge gcc

Yes.

> … That kind of thing? Or is there another way?

You can set environment vars in lots of ways. All are equivalent.  
Since each process has its own environment, and since that environment  
starts out as a copy of that of the parent process, you could even do

$ RAILS\_ENV=development  
$ cd app1  
$ script/server -d -p 3000  
$ RAILS\_ENV=production  
$ cd app2  
$ script/server -d -p 3001

…though I don’t recommend it.

But if you’re not sure how to set environment variables, then please ask  
in a basic Unix forum, not here. It’s really not a Rails issue.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 14, 2009, 7:00pm UTC](https://www.ruby-forum.com/t/rails-very-newbie-question-setting-the-rails-working-mode/180175/8 "2009-12-14T19:00:31Z")

</div>

Marnen Laibow-Koser wrote:

> > > > > Ideally, you’re supposed to set the Rails environment from outside the  
> > > > > app, using the environment variable RAILS\_ENV.
> > 
> > So you mean:  
> > ENV\_RAILS=“production” script/server  
> > ACCEPT\_KEYWORDS="~x86" emerge gcc
> 
> Yes.

Thanks 🙂

> $ RAILS\_ENV=development  
> $ cd app1  
> $ script/server -d -p 3000  
> $ RAILS\_ENV=production  
> $ cd app2  
> $ script/server -d -p 3001
> 
> …though I don’t recommend it.

Ugh, neither do I!

> But if you’re not sure how to set environment variables, then please ask  
> in a basic Unix forum, not here. It’s really not a Rails issue.

I am all self-taught when it comes to Un\*x, I figured that maybe there  
was something I didn’t know.
