# How to set an Environment variable from command line

**URL:** <https://www.ruby-forum.com/t/how-to-set-an-environment-variable-from-command-line/143285>\
**Category:** Rails\
**Created:** [July 17, 2008, 12:05am UTC](https://www.ruby-forum.com/t/how-to-set-an-environment-variable-from-command-line/143285 "2008-07-17T00:05:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecccb3/32.png) [@philipv](https://www.ruby-forum.com/u/philipv)\
**Post date:** [July 17, 2008, 12:05am UTC](https://www.ruby-forum.com/t/how-to-set-an-environment-variable-from-command-line/143285/1 "2008-07-17T00:05:02Z")

</div>

Hello,

I am looking to set a Variable from the command line during starting up  
my server that will be accessible to the whole ruby on rails  
application.

One way of setting such a config variable was putting defining it into  
the environment.rb file but then I don’t know if I could override the  
value of this variable in the environment.rb file when I start up my  
server from the command line.

Thanks  
Philip

---

<div class="post-metadata">

**Author:** ![philipv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecccb3/32.png) [@philipv](https://www.ruby-forum.com/u/philipv)\
**Post date:** [July 17, 2008, 3:48am UTC](https://www.ruby-forum.com/t/how-to-set-an-environment-variable-from-command-line/143285/2 "2008-07-17T03:48:37Z")

</div>

Hi,

You can write this in environment file:

SOME\_CONSTANT = ENV[“SOME\_CONSTANT”] || “A DEFAULT VALUE”

then start rails by

SOME\_CONSTANT=“42” script/server

or it will use default value.

Jan

On Thu, Jul 17, 2008 at 6:05 AM, Philip Varkey \<  
removed\_email\_address@domain.invalid\> wrote:

> server from the command line.
> 
> ## Thanks Philip
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Fly on wheels.
