Hell0
Hell0

Reputation: 349

Setting an appropriate environment to work

Here begins the road. I need to configure a working environment manageable and accessible. I've been reading a bit about environment variables. Windows have an easy configuration, as can be easily changed through window panes. In unix is different ...

export environment_variable = argument eg. export DISPLAY = localhost: 0.0. The question is: should I declare the environment variables when I install rvm? need to work with ruby, and not have to be writing the source myvar each time I start the console.

Same question for node and git. Obviously I ask because in windows if I had to do, and I have unix doubt.

Upvotes: 0

Views: 70

Answers (1)

changingrainbows
changingrainbows

Reputation: 2711

The short answer to your question is No. During the installation, setup and use of rvm, you will not be setting any environment-specific variables that relate to your application, nor for the rubies/gemsets/gems that rvm will be managing for you.

Once rvm is up and running, and you have installed at least one version of ruby (managed by rvm), there are a few options available to you for conveniently managing your environment variables.

a) You can use your unix shell config files (.bashrc, .bash_profile, etc.) to set env variables, but I don't recommend it. This is the equivalent of the Windows scenario you quoted in your question, but is not the common practice in the ruby-unix community.

b) If you are using Rails, environment-specific configurations can be managed in the source code itself, in environment files. For example, production.rb, development.rb, test.rb. etc.

c) If this is a Ruby codebase (i.e. no Rails) then, you can define your environment variables in an 'initializer' file, which can be invoked at the entry point of your ruby project. I typically put my application-specific variables in a yaml file like below.

In file: env_vars.yaml


---
:env_var_a: a.b.com    
:env_var_b: 1111    
:env_var_c: foo    
:env_var_d: bar    

To load these environment variables for use in your codebase,


require 'yaml'
env_vars = YAML.load(File.read(file_path('env_vars.yml')))

If you prefer to not use YAML, you can save the configs in a text file, and use ruby's native File class to access them. I like YAML because it easily creates a hash for me.

Regardless of which option you choose, there is no way you will need to type source every time you start a session

Upvotes: 1

Related Questions