Q:

Environment variables not working in DigitalOcean

I tried to set the environment variables in .bashrc, .profile, .bash_profile, /etc/environment and also in /etc/defaults/nginx but nothing worked.  Only /etc/environment was the file who actually responded echo $MY_VAR output but Rails application didn't picked those variables even after nginx and puma restarted along with daemon-reload other files even didn't responded in terminal (because When i do the ssh it renew the LINUX session).  I'm using these environment variables in my_app/config folder's files.  Can anyone tell a better way to make these variables work.  
I'm using Nginx, Puma, Ruby on Rails 5, Capistrano and Ubuntu 18.04.  Thanks in advance

A:

If you're open to using the Dotenv gem, I used it recently in combination with keeping my environmental vars in .env (be sure to add it to your .gitignore).  The docs for Dotenv explain how to do the setup.  In config/application.rb, you need to add Dotenv::Railtie.load followed by YOUR_SECRECT = ENV['YOUR_SECRECT'] and any other vars you have in .env.  Supposedly, if you're using Capistrano, you should be able to append .env with other linked_files in config/deploy.rb, but I ended up having to add the .env file manually to the shared dir on my server.  Nevertheless, that setup made my environmental variables available to the config/environments/production.rb file. 