0

In my rails application, I exported my database variables in .profile using ansible. the variables are accessible by the command printenv. However, when I run the application or use rails c via ENV['NAME'] , the variables aren't there.

Does anyone have any idea why rails doesn't load variables from .profile?

Ndx
  • 517
  • 2
  • 12
  • 29

1 Answers1

-1

The ~/.profile script is only meant to be read by your (presumably POSIX compatible) shell. And even then only if it is what is known as a "login" shell. For example, from the bash man page:

When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order.

If you're running your rails application from an interactive shell prompt it should have access to the env vars you're setting in ~/.profile. If you're starting your rails app some other way (e.g., from your window manager) then you'll need to find some other way to set the env vars that it inherits.

Kurtis Rader
  • 6,734
  • 13
  • 20
  • I set up my rails application on vagrant running on Ubuntu. It supposed to have access to the env, but it doesnt. – Ndx Dec 22 '20 at 22:33