I am writing an application in Java and I need to use environmental variables in AWS EC2 machine (Linux). I am using System.getenv("myvariable")
in the application to get the particular environment variable. I need to set the permanent environmental variables and currently I have set the variable in ~/.bashrc
, ~/.profile
and also ~/.bash_profile
.
I am giving export myvariable=xyz
in al the 3 files and then I ran source ~/.bashrc
, source ~/.profile
and source ~/.bash_profile
. However I am getting null in the application.
I still don't understand why I am not able to get any environmental variables even though I am exporting the variable in ~/.bash_profile
.I have even checked by running echo $myvariable
and I can see xyz.
If I set the same environment variable in my local MAC machine in the same way I set above and use the same shell to run the same java code, I can see the variable with the value.
So basically I am getting null every time in my AWS EC2 linux machine.
Is there any other place I need to set the variable? I have even restarted the machine but it didn't help.