How to set environment variables by operating system OS for IDEs and CLI
Windows
Can be centrally defined in System Settings and should be set there.
Windows WSL2 env variables should be set like in Linux. For details, see Share Environment Vars between WSL and Windows
Mac
There are several places where you can set environment variables.
For details, see HowTo: Set an Environment Variable in Mac OS X - /etc/<wbr>launchd.conf - Dowd and Associates.
~/.profile
: use this for variables you want to set in all programs launched from the terminal. Note that, unlike on Linux, all shells opened in the Terminal.app are login shells.~/.zshrc
: this is invoked for shells that are not login shells. Use this for aliases and other things that need to be redefined in subshells, not for environment variables that are inherited./etc/profile
: this is loaded before~/.profile
, but is otherwise equivalent. Use it when you want the variable to apply to terminal programs launched by all users on the machine (assuming they use bash).Your user’s
launchd
instance: this applies to all programs launched by the user, GUI, and CLI. You can apply changes at any time by using thesetenv
command inlaunchctl
. In theory, you should be able to putsetenv
commands in~/.launchd.conf
, andlaunchd
would read them automatically when the user logs in, but in practice support for this file was never implemented. Instead, you can use another mechanism to execute a script at login and have that script calllaunchctl
to set up thelaunchd
environment./etc/launchd.conf:
this is read bylaunchd
when the system starts up and when a user logs in. These variables affect every single process on the system, becauselaunchd
is the root process. To apply changes to the running rootlaunchd
you can pipe the commands intosudo launchctl
.
The fundamental things to understand are:
Environment variables are inherited by a process’s children at the time they are forked.
The root process is a
launchd
instance, and there is also a separatelaunchd
instance per user session.launchd
allows you to change its current environment variables usinglaunchctl
; the updated variables are then inherited by all new processes it forks from then on.
You can verify if IntelliJ runs using this environment variable using ps eww -o command <PID> | tr ' ' '\\n'
command.
Linux
For details, see EnvironmentVariables - Community Help Wiki.
Setting
.profile / .bashrc
is not enough for UI apps, as the system does not launch them from the terminal. The relevant variables need to be available to the process that is launching the apps, for example, the window manager.
Important environment variables for IDEs and CLI
CLI
HTTP_PROXY
HTTPS_PROXY
NO_PROXY
PATH
(needs to include directories to Maven and Gradle)JAVA_HOME
...
Java
http.proxyHos
thttps.proxyHost
http.proxyPort
https.proxyPort
Golang
GOPATH
(path to go binaries)GOROOT
(current go installation)
Python
PYTHONPATH
Proxy
Proxy in Java
See Configure HTTP/HTTPS Proxy Settings Java.
Set proxy in Visual Studio Code
See JohannesHoppe/settings.json.
Set proxy in Jetbrains apps
See HTTP Proxy | IntelliJ IDEA.
The Snyk Jetbrains plugin does not read the proxy settings from this configuration. You must set both JAVA Proxy environment variables, as well as the CLI environment variables.
Last updated