Cloud9 environment variables

3.3k views Asked by At

I am developing a Rails 4 app on cloud9 (c9.io). When I placed SECRET="geheim" in config file, it works fine. I tried setting an environment variable using

echo "export SECRET=geheim" >> ~/.profile

and then using ENV['SECRET'] in config file, but it doesn't work. When I type printenv SECRET in console, it returns nothing, meaning the variable is not set. How can I fix this? Thanks.

2

There are 2 answers

0
Hache Laborde On

In the linux terminal:

% export <env-variable-name> = <env-variable-value>

For example, setting an AWS-S3 bucket:

% export PHOTOS_BUCKET='s3://edx-photo-lab/photos/'

source: https://docs.aws.amazon.com/cloud9/latest/user-guide/env-vars.html

The above solution has the problem that the variables are cleared when the Cloud9 EC2 is rebooted. To persist the variable you must add the export statement to the ~/.bashrc. You could use vim for edit:

% sudo vim ~/.bashrc
2
Algis On

You can add environment variables on cloud9 only if you are using the run panel to run your application. In the run panel theres a ENV button at the far right side where you can set your environment variables.

Heres some documentation about setting up your run command:
https://docs.c9.io/v1.0/docs/run-an-application

Unfortunately, this doesnt work if you're running your app from the terminal as cloud9 doesnt seem to support environment variables directly from the terminal.