I set an environment variable in /etc/environment, but it's not in printenv using bash.exe with Windows cmd. Why? [duplicate]

Solution 1:

There are several methods for bash on Windows

See https://github.com/Microsoft/WSL/issues/24

Basically you add them to ~/.bashrc

If that is not working post your .bashrc

I don't know why /etc/environment is not working.

Solution 2:

Old post but if anyone stumbles here from google...

As of Windows version 17134, adding the -i flag to the bash command will run the shell command as "interactive" which will invoke the full linux environment including any login dot files that are set up (.bashrc, .bash_aliases, etc.) which might hold environmental or variable definitions.

For the original question, from Windows cmd this should have the desired effect: bash -ic printenv

See also: bash -ic 'man bash'