1

In my Linux user .bashrc file for the user account I run under when doing Linux based development, I set an environment variable to let my apps know they are running in the development environment as opposed to running under the production environment:

LINUX_DEV=true
export LINUX_DEV # Make LINUX_DEV an environment variable

If I open a new Terminal window and run the following I do see the setting:

$>printenv | grep LINUX_DEV
$>LINUX_DEV=true

All is well. However, when I run WebStorm/IntelliJ, and use it's internal facility to launch a Terminal window, the environment variable can not be found:

$>printenv | grep LINUX_DEV
$>

If I execute the whoami command from either an external Terminal window or from the Terminal window launched by WebStorm, I get the exact same user name (my user name for the user account I run while on my local Linux box), so it's not a problem with different user accounts. I have already tried a full restart of my system to make sure it's not a transient issue. The problem persists.

Is WebStorm/IntelliJ running in some strange way that it can't access the environment variables set for the local user account? If the IDE was running as a background service or some other exotic executable context I could understand this, but as I said I launch it as a regular app under my user account and the whoami command shows the exact same user name as an external Terminal window does.

This is a real problem because when I try to use the Node.JS process.env variable and get the value of process.env.LINUX_DEV, that variable is undefined naturally due to this problem. How can I get this working properly?

NOTE: I did try putting the exact same environment variable setting in my /etc/environment file. I had to do a full restart to get WebStorm's Terminal window to see the changes but it did work. However, I would prefer to have the setting in my local user account so if anyone knows why I'm having this problem with setting it in .bashrc, I'd like to know.

UPDATE: Although the environment variable set in the /etc/environment file is visible from a WebStorm Terminal window, it is not visible via the Node.JS process.env variable so I'm still out of luck. I'm truly amazed that this is so difficult at this point.

1 Answer 1

0

I'm posting this answer to save others from the same pain I just went through. The reason I couldn't access the environment variables from my WebStorm/Node.JS app is because I didn't have the NPM "process" module installed. Once I installed that module, process.env started working for me. I used the following command to install it, launched from a Terminal window set to the top level directory that contains my Node.JS app:

$>sudo NPM -g install process --save
4
  • strange... process.env is a part o Node.js core, no additional modules normally need to be installed
    – lena
    Commented Mar 1, 2017 at 11:43
  • 5
    Just a note: WebStorm correctly loads environment variables from .bashrc when being started from terminal; however, environment variables mismatch occurs if IDE is launched from Desktop or System menu. The problem is that IDE sees environment variables configured in ~/.profile (login shell), but not in interactive shell configuration files (like ~/.bashrc). And, to make things worse, some tools (nvm, for example) alter .bashrc only during their installation phase. So, indeed, you may face issues when running your Node application from WebStorm if the latter was started from desktop, etc.
    – lena
    Commented Mar 1, 2017 at 11:48
  • @lena - appreciate the tip. Not sure what to say but I triple-checked my results including intervening system restarts. Nothing worked via either .bashrc, /etc/environment, or adding environment variables to the WebStorm run configuration until I installed the "process" package with NPM. Commented Mar 1, 2017 at 12:26
  • 1
    @lena: thanks for the help. It worked for me without needing to install process module.
    – Sam
    Commented Aug 13, 2018 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .