gpt4 book ai didi

java - System.getenv 找不到环境变量

转载 作者:行者123 更新时间:2023-11-30 03:18:10 25 4
gpt4 key购买 nike

我在 EC2 上的 Ubuntu 实例上获取环境变量时遇到问题。

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

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 解释器时,我尝试执行以下操作:

^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 中,但没有成功。

最佳答案

我发现问题是使用 sudo 命令运行它。它会导致您的环境变量被覆盖。要保存环境变量,请使用 -E 标志运行它,即

sudo -E sbt 控制台

关于java - System.getenv 找不到环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32016965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com