Ahmed Aswani Ahmed Aswani - 1 year ago 122
Linux Question

How to keep Environment Variables when Using SUDO

When I use any command with sudo the enviroment variables are not there. For example after setting HTTP_PROXY the command

works fine without
. However if I type
sudo wget
it says it can't bypass the proxy setting.

Answer Source

The trick is to add environment variables to sudoers file via sudo visudo command and add these lines:

Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy"

taken from ArchLinux wiki.

For Ubuntu 14, you need to specify in separate lines as it returns the errors for multi-variable lines:

Defaults  env_keep += "http_proxy"
Defaults  env_keep += "https_proxy"
Defaults  env_keep += "HTTP_PROXY"
Defaults  env_keep += "HTTPS_PROXY"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download