问题描述
如何为Digital Ocean上托管的Rails应用持久化环境变量?
How can I persist environment variables for my Rails app hosted on Digital Ocean?
我在本地运行带有 export SERVICE_USERNAME ='somekey'
这样的命令的bash脚本.
Locally I run a bash script with commands like, export SERVICE_USERNAME='somekey'
.
但是,当我尝试手动运行 export SERVICE_USERNAME ='somekey'
时,在ssh-ing到Ubuntu服务器时,它们仅在会话中持续使用……这对我的应用没有帮助.
But when I try to manually run export SERVICE_USERNAME='somekey'
, while ssh-ing onto the Ubuntu server, they only last for the session... which is not helpful for my app.
如何在Digital Ocean上保留环境变量?有没有简单的方法?
How can I persist environment variables on Digital Ocean? Is there a simple way?
推荐答案
您可以将环境变量设置为用户(在用户的〜/.profile或〜./pam_environment文件中)或系统范围内(在/etc/环境文件)
You can either set your environment variables to the user (in the ~/.profile or ~./pam_environment files of the user) or system wide (in the /etc/environment file)
您可以在 Ubuntu文档中找到更多信息.
You can find more info on this Ubuntu documentation.
编辑;
您可以使用脚本来执行此操作:
You could have your script to do this:
sudo echo 'export SERVICE_USERNAME="somekey"' >> /etc/environment
这篇关于在Digital Ocean上持久化Rails应用程序的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!