首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.getenv找不到环境变量

System.getenv找不到环境变量
EN

Stack Overflow用户
提问于 2015-08-14 18:54:55
回答 2查看 947关注 0票数 1

我在EC2的Ubuntu上很难获得环境变量。

下面是我的/etc/environment文件中的内容:

代码语言:javascript
复制
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
DATABASE_URL="postgres://postgres:postgres@localhost:5432/suredbitsweb"

现在,当我加载Scala解释器时,我尝试执行以下操作:

代码语言:javascript
复制
^Cubuntu@ip-172-31-35-31:~/suredbits-web$ sudo sbt console
[info] Loading project definition from /home/ubuntu/suredbits-web/project
[info] Set current project to suredbits-web (in build file:/home/ubuntu/suredbits-web/)
[info] Downloading Bower dependencies for suredbits-web
[info] https://github.com/MrRio/jsPDF.git#1.0.272
[info] 1.0.272 against https://github.com/MrRio/jsPDF.git#~1.0.272
[info] git://github.com/bitpay/bitcore-ecies.git#0.10.2
[info] 0.10.2 against git://github.com/bitpay/bitcore-ecies.git#^0.10.0
[info] git://github.com/bitpay/bitcore.git#0.10.4
[info] 0.10.4 against git://github.com/bitpay/bitcore.git#^0.10.4
[info] git://github.com/bitpay/bitcore-explorers.git#0.10.4
[info] 0.10.4 against git://github.com/bitpay/bitcore-explorers.git#~0.10.4
[info] git://github.com/bitpay/bitcore-message.git#0.10.1
[info] 0.10.1 against git://github.com/bitpay/bitcore-message.git#~0.10.1
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.4 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.

scala> System.getenv("PATH");
res0: String = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

scala> System.getenv("DATABASE_URL");
res1: String = null

scala> 

我已经“重新启动”了我的EC2实例,希望这将有助于获取新的环境变量。我还尝试将环境变量添加到我的~/.bashrc中,但它没有工作。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-14 19:27:37

我看到问题是用sudo命令运行的。它会导致环境变量的重写。若要保存环境变量,请使用-E标志运行它,即

sudo -E sbt console

票数 2
EN

Stack Overflow用户

发布于 2015-08-14 19:22:46

首先,检查echo $PATHecho $DATABASE_URL的输出。

其次,检查是否从正确的用户启动scala解释器。

FYI:分号在scala中是不必要的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32016965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档