简体   繁体   中英

System.getenv not finding envrionment variables

I am having trouble getting envrionment variables on my Ubuntu insance on EC2.

Here is what is in my /etc/environment file:

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"

now when I load up a Scala interpreter I try and do the following:

^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> 

I have 'rebooted' my EC2 instance hoping that that would help pick up the new environment variable. I also have tried adding the environment variable to my ~/.bashrc which didn't work.

I see that the issue is running it with sudo command. It causes the overriding of your environmental variables. To save your environmental variables, run it with the -E flag, ie

sudo -E sbt console

First, check outputs for echo $PATH and echo $DATABASE_URL .

Second, check that you launch scala interpreter from right user.

FYI: semicolon is not necessary in scala.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM