簡體   English   中英

System.getenv找不到環境變量

[英]System.getenv not finding envrionment variables

我在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 console

首先,檢查輸出是否為echo $PATHecho $DATABASE_URL

其次,檢查您是否從正確的用戶啟動了scala解釋器。

僅供參考:scala中不需要分號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM