I was trying to set up a system similar to heroku where I would store secret keys in environmental variables and then access them from my rails app like this:
我试图建立一个类似于heroku的系统,我将环境变量中的密钥存储在其中,然后从我的rails应用程序中访问它们,如下所示:
secret = ENV['EMAIL_PASSWORD']
I know heroku lets you do heroku config:add EMAIL_PASSWORD=secret
, and I wanted to do something like that for my own ubuntu box running nginx and Passenger.
我知道heroku允许你做heroku配置:添加EMAIL_PASSWORD=secret,我想为我自己的运行nginx和Passenger的ubuntu框做类似的事情。
Should I add these variables as export
s in .bashrc
or .bash_login
so that on system reboot these variables are automatically set?
我应该在.bashrc或.bash_login中添加这些变量作为导出,以便在系统重新启动时自动设置这些变量吗?
I'm not sure when each of those files gets read in.
我不确定这些文件何时被读取。
13 个解决方案
#1
10
You can use dotenv gem which loads the .env file as environmental variables. You can generate the .env file for different environments, and need not be rather should not checked into your repository.
您可以使用dotenv gem作为环境变量加载.env文件。您可以为不同的环境生成.env文件,而不必签入您的存储库。
#2
7
Keep in mind that nginx may not be running under the same environment as you are, and usually (pronounced "Apache") we add env-vars in the server config file via SetEnv. However, nginx doesn't have such a feature... nor does it need one, I believe.
请记住,nginx可能不像您所处的环境一样运行,并且通常(读作“Apache”)我们通过SetEnv在服务器配置文件中添加env-vars。然而,nginx没有这样的功能……我相信它也不需要一个。
sudo -E /usr/local/sbin/nginx
When running nginx for it to be aware of your own user env vars.
运行nginx时,让它知道自己的用户env vars。
Or, check out the env
command (see here):
或者,查看env命令(参见这里):
env EMAIL_PASSWORD=secret
To answer your question, yes, you should use export
statements in your shell config files.
要回答您的问题,您应该在shell配置文件中使用export语句。
#3
6
(this is probably a overkill, but maybe it'll be useful)
(这可能有点夸张,但可能会有用)
Some things to keep in mind:
要记住以下几点:
Environment variables are somewhat public, and can be seen by other processes as easily as added an option to the ps(1)
command (like ps e $$
in bash) or looking at /proc/*/environ
, though both are restricted at least to the same user (or root) on modern systems. Don't rely on them being secret if you have another fairly easy option available.
环境变量在某种程度上是公开的,并且可以通过其他流程看到,就像在ps(1)命令中添加一个选项(比如在bash中使用ps e $$),或者查看/proc/ dev / Environment,尽管它们在现代系统中至少对同一用户(或根)都有限制。如果你有另一个相当容易的选择,不要把它们当作秘密。
~/.bashrc
is the wrong place for environment variables, since they can be computed once at login in ~/.bash_login
, ~/.bash_profile, or ~/.profile
, depending on your usage, and passed down to all descendent shells. In contrast, ~/.bashrc
actions tend to be recomputed on every shell invocation (unless explicitly disabled).
~ /。bashrc对于环境变量来说是错误的,因为它们可以在登录时计算一次~/。bash_login ~ /。bash_profile、~ /。配置文件,根据您的使用情况,并传递到所有的后代shell。相比之下,~ /。bashrc操作倾向于在每次shell调用中重新计算(除非显式禁用)。
Putting bash code in the ~/.profile
can confuse other sh-descendent shells and non-shell tools which try to read that file, so having the bash-specific ~/.bash_login
or -_profile contain the bash-specific things, and using . ~/.profile
for the more general things (LESS, EDITOR, VISUAL, LC_COLLATE, LS_COLORS, etc), is friendlier to the other tools.
将bash代码放在~/中。概要文件可以混淆其他的sh-派生shell和非shell工具,它们试图读取该文件,因此具有特定于bash的~/。bash_login或-_profile包含特定于bash的内容和使用。~ /。对于更一般的东西(较少的、编辑器、可视化、LC_COLLATE、LS_COLORS等)的概要文件,对其他工具更友好。
Environment variables in ~/.profile
should be in the old Bourne shell form (VAR=value ; export VAR
). On Linux, this isn't usually critical, though on other Unixen this can be a big issue when an older version of "sh" tries to read them.
在~ /环境变量。配置文件应该采用旧的Bourne shell格式(VAR=value;出口VAR)。在Linux上,这通常并不重要,但在其他unix上,当旧版本的“sh”试图读取它们时,这可能是一个大问题。
Some X sessions will only read ~/.profile
, not ~/.bash_login
or the others mentioned above. Some will look for a ~/.xsession
file will need to be modified to have . $HOME/.profile
if it doesn't already somehow.
有些课程只会读~/。配置文件,而不是~ /。bash_login或上面提到的其他文件。有些人会寻找~/。需要将xsession文件修改为具有。$ HOME /。如果它还不存在的话。
System-wide settings would be put instead in something like /etc/profile.d/similar-to-heroku.sh
. Note that the ".sh" is only present since the file will be used with "." or "source" - shell scripts should never have command-name extensions in any form of Unix/Linux.
系统范围的设置将被放置在/etc/ profile.d/similaroku .sh中。注意”。sh是唯一存在的,因为该文件将与“.”或“source”一起使用。
Most environment variables get ditched when one sudo
s to root, as ybakos points out. Similar issues show up in crontabs, at jobs, etc. When in doubt, adding env | sort > /tmp/envvars
or the like a suspect script can really help in debugging.
正如ybakos所指出的那样,当一件sudos变成根时,大多数环境变量都会被抛弃。类似的问题出现在crontabs、作业等等中。如果有疑问,添加env | sort > /tmp/ envars或类似的可疑脚本可以真正帮助调试。
Be aware some distributions have shell startup scripts so contorted they end up actually defying the order given in the bash(1) manual page. Anytime you find a default user ~/.profile
checking for $BASH or $BASH_VERSION, you may be in one of these, um..., "interesting" environments, and may have to read through them to figure out where the control flow goes (they should be using a bash-specific ~/.bash_profile
or ~/.bash_login
, which includes the more generic ~/.profile
by reference, thus letting the bash executable do the work instead of having to write $BASH checks in shell code).
请注意,有些发行版的shell启动脚本如此扭曲,以至于它们实际上违背了bash(1)手册页中给出的顺序。任何时候你发现一个默认的用户~/。$BASH或$BASH_VERSION的概要检查,您可能在其中之一,嗯……,“有趣”的环境,并且可能需要通读它们以确定控制流的去向(它们应该使用一个特定于bash的~/。bash_profile或~ /。bash_login,其中包含更通用的~/。通过引用配置文件,从而让bash可执行程序完成工作,而不必在shell代码中编写$ bash检查)。
~/.bash_profile
(or ~/.bash_login
) can certainly include . ~/.bashrc
, but the environment variables belong in the ~/.bash_profile
(if bash-specific) or the ~/.profile
included from it (if you're using this mechanism and have envvars for everything else in there) as DeWitt says, just remember to put the . ~/.bashrc
AFTER the .bash_profile's . ~/.profile
and other environment variables, so that both login and all other invocations of the ~/.bashrc
can rely on the envvars already being set. An Example ~/.bash_profile
:
~ /。bash_profile(或~/.bash_login)当然可以包括。~ /。bashrc,但是环境变量属于~/。bash_profile(如果是bash专用的)或~/。正如DeWitt所言,它包含的概要文件(如果您正在使用这种机制,并且在其中的其他所有东西都有envars),请记住将。~ /。bashrc位于.bash_profile之后。~ /。配置文件和其他环境变量,使登录和所有其他调用的~/。bashrc可以依赖于已经设置的envars。
# .bash_profile
[ -r ~/.profile ] && . ~/.profile # envvars
[ -r ~/.bashrc ] && . ~/.bashrc # functions, per-tty settings, etc.
#---eof
The [ -r ... ] && ...
works in any Bourne shell descendent and doesn't cause errors/aborts if the .profile is missing (I personally have a ~/.profile.d/*.sh
setup as well, but this is left as an entirely optional exercise).
(- r……& &…在任何Bourne shell子代中工作,如果.profile丢失,不会导致错误/中止(我个人有一个~/.profile.d/*)。sh设置也一样,但是这是一个完全可选的练习)。
Note that bash only reads the first file of these three which it finds:
请注意,bash仅读取它找到的这三个文件中的第一个文件:
~/.bash_profile
~/.bash_login
~/.profile
...so once you have that one, the use of the other two is entirely under control of the user, from bash's perspective.
…所以一旦你有了这个,其他两个的使用就完全在用户的控制下,从bash的角度来看。
#4
4
This is documented in nginx. It removes all environment variables except TZ
when running the workers. If you want to add an environment variable, add the following to the top of the nginx configuration:
这在nginx中有记录。它在运行worker时删除了除TZ之外的所有环境变量。如果要添加环境变量,请在nginx配置的顶部添加以下内容:
# The top of the configuration usually has things like:
user user-name;
pid pid-file-name;
# Add to this:
env VAR1=value1;
env VAR2=value2;
# OR simply add:
env VAR1;
# To inherit the VAR1 from whatever you set in bash
The normal export
or anything you do in bash has no guarantee of getting passed on to nginx, due to the way the init scripts are written (we don't know if they're using sudo with a clean environment, etc). So I'd rather put these in the nginx configuration file itself, rather than depending on the shell to do it.
由于init脚本的编写方式(我们不知道他们是否在干净的环境中使用sudo,等等),在bash中进行的常规导出或任何操作都不能保证传递给nginx。所以我宁愿把它们放在nginx配置文件中,而不是依赖于shell。
Edit: Fix link
编辑:修复链接
#5
4
I have a script in /usr/local/bin
folder that sets some env vars and then executes Ruby. I define the path to Ruby in my (Apache, not Nginx) conf file to that file in /usr/local/bin
.
我在/usr/local/bin文件夹中有一个脚本,它设置一些env vars,然后执行Ruby。我在/usr/local/ binf文件(Apache,而不是Nginx)中定义到Ruby的路径。
example:
例子:
#!/bin/sh
# setup env vars here
export FOO=bar
export PATH_TO_FOO=/bar/bin
export PATH=$PATH:PATH_TO_FOO
# and execute Ruby with any arguments passed to this script
exec "/usr/bin/ruby" "$@"
#6
2
You should read this response to another question, it will help:
你应该读一下对另一个问题的回答,它会有帮助:
https://*.com/a/11765775/1217298
https://*.com/a/11765775/1217298
#7
2
I put them in my nginx config, specifically in the server definition for the app using the passenger_env_var
command:
我将它们放在我的nginx配置中,特别是在使用passenger er_env_var命令的应用服务器定义中:
server { server_name www.foo.com; root /webapps/foo/public; passenger_enabled on; passenger_env_var DATABASE_USERNAME foo_db; passenger_env_var DATABASE_PASSWORD secret; passenger_env_var SECRET_KEY_BASE the_secret_keybase; }
This works for me. See the phusion passenger docs for more info.
这适合我。有关更多信息,请参阅合并乘客医生。
#8
1
EDITED :
编辑:
Ok sorry i read it too fast, you can check how to save your ENV variables here :
对不起,我读得太快了,你可以看看如何保存ENV变量:
https://help.ubuntu.com/community/EnvironmentVariables
https://help.ubuntu.com/community/EnvironmentVariables
http://www.cyberciti.biz/faq/set-environment-variable-linux/
http://www.cyberciti.biz/faq/set-environment-variable-linux/
If you use Nginx as server on your local computer, you can define your env variable into your nginx config file.
如果您在本地计算机上使用Nginx作为服务器,您可以在Nginx配置文件中定义env变量。
location / {
...
fastcgi_param EMAIL_PASSWORD secret; #EMAIL_PASSWORD = secret
...
}
#9
1
I'm using rbenv as a version manager. Good solution to store environment variables for the project was installing the rbenv-vars plugin and putting them in .rbenv-vars
file.
我使用rbenv作为版本管理器。为这个项目存储环境变量的一个很好的解决方案是安装rbenv-vars插件并将它们放入.rbenv-vars文件中。
Here is a useful post:
Deploying app ENV variables with Rbenv, Passenger and Capistrano
这里有一个有用的帖子:使用Rbenv、Passenger和Capistrano部署app ENV变量
#10
1
For those battling this that are using RVM. Make sure that your default environments file is including your user's .bashrc and .profile files
对于那些使用RVM的人来说。确保您的默认环境文件包含用户的.bashrc和.profile文件
file: $rvm_path/environments/default
to find the path run this command:
要找到路径,请运行以下命令:
ls -lah `whereis rvm`/environments/default
add these two lines before the first line in that file:
在该文件的第一行之前添加这两行:
source $HOME/.bashrc
source $HOME/.profile
#11
0
In case anyone had the same type of question as I did, here's a nice little writeup about the different .bash*
files: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
如果有人和我有同样的问题,这里有一个关于不同的。bash*文件的好文章:http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html。
In summary:
总而言之:
For the most part: .bash_profile
is read when you log into the computer and .bashrc
is read when you start a new terminal. For Mac OSX .bash_profile
is read with every terminal window you start.
在大多数情况下:.bash_profile将在登录到计算机时读取,而.bashrc将在启动新终端时读取。对于Mac OSX .bash_profile,将在启动的每个终端窗口中读取。
So, the recommended procedure is to source .bashrc
from .bash_profile
so all the variables are set when you login to the computer. Just add this to .bash_profile
:
因此,推荐的过程是从.bash_profile中获取.bashrc,以便在登录到计算机时设置所有变量。只需将此添加到.bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
#12
0
The best place to keep env variables for your project is /etc/profile.d/YOUR_FILE.sh, Here you can find the documentation which explains in details where to keep env variables for different scenarios.
为您的项目保存环境变量的最佳位置是/etc/profile.d/ your_file。在这里,您可以找到文档,其中详细说明了在不同场景中保存env变量的位置。
#13
-1
You have to add the export lines into your .profile file under your home folder...
您必须将导出行添加到主文件夹下的.profile文件中……
Environment variables are being set on login...
在登录时环境变量被设置……
#1
10
You can use dotenv gem which loads the .env file as environmental variables. You can generate the .env file for different environments, and need not be rather should not checked into your repository.
您可以使用dotenv gem作为环境变量加载.env文件。您可以为不同的环境生成.env文件,而不必签入您的存储库。
#2
7
Keep in mind that nginx may not be running under the same environment as you are, and usually (pronounced "Apache") we add env-vars in the server config file via SetEnv. However, nginx doesn't have such a feature... nor does it need one, I believe.
请记住,nginx可能不像您所处的环境一样运行,并且通常(读作“Apache”)我们通过SetEnv在服务器配置文件中添加env-vars。然而,nginx没有这样的功能……我相信它也不需要一个。
sudo -E /usr/local/sbin/nginx
When running nginx for it to be aware of your own user env vars.
运行nginx时,让它知道自己的用户env vars。
Or, check out the env
command (see here):
或者,查看env命令(参见这里):
env EMAIL_PASSWORD=secret
To answer your question, yes, you should use export
statements in your shell config files.
要回答您的问题,您应该在shell配置文件中使用export语句。
#3
6
(this is probably a overkill, but maybe it'll be useful)
(这可能有点夸张,但可能会有用)
Some things to keep in mind:
要记住以下几点:
Environment variables are somewhat public, and can be seen by other processes as easily as added an option to the ps(1)
command (like ps e $$
in bash) or looking at /proc/*/environ
, though both are restricted at least to the same user (or root) on modern systems. Don't rely on them being secret if you have another fairly easy option available.
环境变量在某种程度上是公开的,并且可以通过其他流程看到,就像在ps(1)命令中添加一个选项(比如在bash中使用ps e $$),或者查看/proc/ dev / Environment,尽管它们在现代系统中至少对同一用户(或根)都有限制。如果你有另一个相当容易的选择,不要把它们当作秘密。
~/.bashrc
is the wrong place for environment variables, since they can be computed once at login in ~/.bash_login
, ~/.bash_profile, or ~/.profile
, depending on your usage, and passed down to all descendent shells. In contrast, ~/.bashrc
actions tend to be recomputed on every shell invocation (unless explicitly disabled).
~ /。bashrc对于环境变量来说是错误的,因为它们可以在登录时计算一次~/。bash_login ~ /。bash_profile、~ /。配置文件,根据您的使用情况,并传递到所有的后代shell。相比之下,~ /。bashrc操作倾向于在每次shell调用中重新计算(除非显式禁用)。
Putting bash code in the ~/.profile
can confuse other sh-descendent shells and non-shell tools which try to read that file, so having the bash-specific ~/.bash_login
or -_profile contain the bash-specific things, and using . ~/.profile
for the more general things (LESS, EDITOR, VISUAL, LC_COLLATE, LS_COLORS, etc), is friendlier to the other tools.
将bash代码放在~/中。概要文件可以混淆其他的sh-派生shell和非shell工具,它们试图读取该文件,因此具有特定于bash的~/。bash_login或-_profile包含特定于bash的内容和使用。~ /。对于更一般的东西(较少的、编辑器、可视化、LC_COLLATE、LS_COLORS等)的概要文件,对其他工具更友好。
Environment variables in ~/.profile
should be in the old Bourne shell form (VAR=value ; export VAR
). On Linux, this isn't usually critical, though on other Unixen this can be a big issue when an older version of "sh" tries to read them.
在~ /环境变量。配置文件应该采用旧的Bourne shell格式(VAR=value;出口VAR)。在Linux上,这通常并不重要,但在其他unix上,当旧版本的“sh”试图读取它们时,这可能是一个大问题。
Some X sessions will only read ~/.profile
, not ~/.bash_login
or the others mentioned above. Some will look for a ~/.xsession
file will need to be modified to have . $HOME/.profile
if it doesn't already somehow.
有些课程只会读~/。配置文件,而不是~ /。bash_login或上面提到的其他文件。有些人会寻找~/。需要将xsession文件修改为具有。$ HOME /。如果它还不存在的话。
System-wide settings would be put instead in something like /etc/profile.d/similar-to-heroku.sh
. Note that the ".sh" is only present since the file will be used with "." or "source" - shell scripts should never have command-name extensions in any form of Unix/Linux.
系统范围的设置将被放置在/etc/ profile.d/similaroku .sh中。注意”。sh是唯一存在的,因为该文件将与“.”或“source”一起使用。
Most environment variables get ditched when one sudo
s to root, as ybakos points out. Similar issues show up in crontabs, at jobs, etc. When in doubt, adding env | sort > /tmp/envvars
or the like a suspect script can really help in debugging.
正如ybakos所指出的那样,当一件sudos变成根时,大多数环境变量都会被抛弃。类似的问题出现在crontabs、作业等等中。如果有疑问,添加env | sort > /tmp/ envars或类似的可疑脚本可以真正帮助调试。
Be aware some distributions have shell startup scripts so contorted they end up actually defying the order given in the bash(1) manual page. Anytime you find a default user ~/.profile
checking for $BASH or $BASH_VERSION, you may be in one of these, um..., "interesting" environments, and may have to read through them to figure out where the control flow goes (they should be using a bash-specific ~/.bash_profile
or ~/.bash_login
, which includes the more generic ~/.profile
by reference, thus letting the bash executable do the work instead of having to write $BASH checks in shell code).
请注意,有些发行版的shell启动脚本如此扭曲,以至于它们实际上违背了bash(1)手册页中给出的顺序。任何时候你发现一个默认的用户~/。$BASH或$BASH_VERSION的概要检查,您可能在其中之一,嗯……,“有趣”的环境,并且可能需要通读它们以确定控制流的去向(它们应该使用一个特定于bash的~/。bash_profile或~ /。bash_login,其中包含更通用的~/。通过引用配置文件,从而让bash可执行程序完成工作,而不必在shell代码中编写$ bash检查)。
~/.bash_profile
(or ~/.bash_login
) can certainly include . ~/.bashrc
, but the environment variables belong in the ~/.bash_profile
(if bash-specific) or the ~/.profile
included from it (if you're using this mechanism and have envvars for everything else in there) as DeWitt says, just remember to put the . ~/.bashrc
AFTER the .bash_profile's . ~/.profile
and other environment variables, so that both login and all other invocations of the ~/.bashrc
can rely on the envvars already being set. An Example ~/.bash_profile
:
~ /。bash_profile(或~/.bash_login)当然可以包括。~ /。bashrc,但是环境变量属于~/。bash_profile(如果是bash专用的)或~/。正如DeWitt所言,它包含的概要文件(如果您正在使用这种机制,并且在其中的其他所有东西都有envars),请记住将。~ /。bashrc位于.bash_profile之后。~ /。配置文件和其他环境变量,使登录和所有其他调用的~/。bashrc可以依赖于已经设置的envars。
# .bash_profile
[ -r ~/.profile ] && . ~/.profile # envvars
[ -r ~/.bashrc ] && . ~/.bashrc # functions, per-tty settings, etc.
#---eof
The [ -r ... ] && ...
works in any Bourne shell descendent and doesn't cause errors/aborts if the .profile is missing (I personally have a ~/.profile.d/*.sh
setup as well, but this is left as an entirely optional exercise).
(- r……& &…在任何Bourne shell子代中工作,如果.profile丢失,不会导致错误/中止(我个人有一个~/.profile.d/*)。sh设置也一样,但是这是一个完全可选的练习)。
Note that bash only reads the first file of these three which it finds:
请注意,bash仅读取它找到的这三个文件中的第一个文件:
~/.bash_profile
~/.bash_login
~/.profile
...so once you have that one, the use of the other two is entirely under control of the user, from bash's perspective.
…所以一旦你有了这个,其他两个的使用就完全在用户的控制下,从bash的角度来看。
#4
4
This is documented in nginx. It removes all environment variables except TZ
when running the workers. If you want to add an environment variable, add the following to the top of the nginx configuration:
这在nginx中有记录。它在运行worker时删除了除TZ之外的所有环境变量。如果要添加环境变量,请在nginx配置的顶部添加以下内容:
# The top of the configuration usually has things like:
user user-name;
pid pid-file-name;
# Add to this:
env VAR1=value1;
env VAR2=value2;
# OR simply add:
env VAR1;
# To inherit the VAR1 from whatever you set in bash
The normal export
or anything you do in bash has no guarantee of getting passed on to nginx, due to the way the init scripts are written (we don't know if they're using sudo with a clean environment, etc). So I'd rather put these in the nginx configuration file itself, rather than depending on the shell to do it.
由于init脚本的编写方式(我们不知道他们是否在干净的环境中使用sudo,等等),在bash中进行的常规导出或任何操作都不能保证传递给nginx。所以我宁愿把它们放在nginx配置文件中,而不是依赖于shell。
Edit: Fix link
编辑:修复链接
#5
4
I have a script in /usr/local/bin
folder that sets some env vars and then executes Ruby. I define the path to Ruby in my (Apache, not Nginx) conf file to that file in /usr/local/bin
.
我在/usr/local/bin文件夹中有一个脚本,它设置一些env vars,然后执行Ruby。我在/usr/local/ binf文件(Apache,而不是Nginx)中定义到Ruby的路径。
example:
例子:
#!/bin/sh
# setup env vars here
export FOO=bar
export PATH_TO_FOO=/bar/bin
export PATH=$PATH:PATH_TO_FOO
# and execute Ruby with any arguments passed to this script
exec "/usr/bin/ruby" "$@"
#6
2
You should read this response to another question, it will help:
你应该读一下对另一个问题的回答,它会有帮助:
https://*.com/a/11765775/1217298
https://*.com/a/11765775/1217298
#7
2
I put them in my nginx config, specifically in the server definition for the app using the passenger_env_var
command:
我将它们放在我的nginx配置中,特别是在使用passenger er_env_var命令的应用服务器定义中:
server { server_name www.foo.com; root /webapps/foo/public; passenger_enabled on; passenger_env_var DATABASE_USERNAME foo_db; passenger_env_var DATABASE_PASSWORD secret; passenger_env_var SECRET_KEY_BASE the_secret_keybase; }
This works for me. See the phusion passenger docs for more info.
这适合我。有关更多信息,请参阅合并乘客医生。
#8
1
EDITED :
编辑:
Ok sorry i read it too fast, you can check how to save your ENV variables here :
对不起,我读得太快了,你可以看看如何保存ENV变量:
https://help.ubuntu.com/community/EnvironmentVariables
https://help.ubuntu.com/community/EnvironmentVariables
http://www.cyberciti.biz/faq/set-environment-variable-linux/
http://www.cyberciti.biz/faq/set-environment-variable-linux/
If you use Nginx as server on your local computer, you can define your env variable into your nginx config file.
如果您在本地计算机上使用Nginx作为服务器,您可以在Nginx配置文件中定义env变量。
location / {
...
fastcgi_param EMAIL_PASSWORD secret; #EMAIL_PASSWORD = secret
...
}
#9
1
I'm using rbenv as a version manager. Good solution to store environment variables for the project was installing the rbenv-vars plugin and putting them in .rbenv-vars
file.
我使用rbenv作为版本管理器。为这个项目存储环境变量的一个很好的解决方案是安装rbenv-vars插件并将它们放入.rbenv-vars文件中。
Here is a useful post:
Deploying app ENV variables with Rbenv, Passenger and Capistrano
这里有一个有用的帖子:使用Rbenv、Passenger和Capistrano部署app ENV变量
#10
1
For those battling this that are using RVM. Make sure that your default environments file is including your user's .bashrc and .profile files
对于那些使用RVM的人来说。确保您的默认环境文件包含用户的.bashrc和.profile文件
file: $rvm_path/environments/default
to find the path run this command:
要找到路径,请运行以下命令:
ls -lah `whereis rvm`/environments/default
add these two lines before the first line in that file:
在该文件的第一行之前添加这两行:
source $HOME/.bashrc
source $HOME/.profile
#11
0
In case anyone had the same type of question as I did, here's a nice little writeup about the different .bash*
files: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
如果有人和我有同样的问题,这里有一个关于不同的。bash*文件的好文章:http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html。
In summary:
总而言之:
For the most part: .bash_profile
is read when you log into the computer and .bashrc
is read when you start a new terminal. For Mac OSX .bash_profile
is read with every terminal window you start.
在大多数情况下:.bash_profile将在登录到计算机时读取,而.bashrc将在启动新终端时读取。对于Mac OSX .bash_profile,将在启动的每个终端窗口中读取。
So, the recommended procedure is to source .bashrc
from .bash_profile
so all the variables are set when you login to the computer. Just add this to .bash_profile
:
因此,推荐的过程是从.bash_profile中获取.bashrc,以便在登录到计算机时设置所有变量。只需将此添加到.bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
#12
0
The best place to keep env variables for your project is /etc/profile.d/YOUR_FILE.sh, Here you can find the documentation which explains in details where to keep env variables for different scenarios.
为您的项目保存环境变量的最佳位置是/etc/profile.d/ your_file。在这里,您可以找到文档,其中详细说明了在不同场景中保存env变量的位置。
#13
-1
You have to add the export lines into your .profile file under your home folder...
您必须将导出行添加到主文件夹下的.profile文件中……
Environment variables are being set on login...
在登录时环境变量被设置……