How to keep environment variables when using sudo

前端 未结 6 830
滥情空心
滥情空心 2020-11-22 01:55

When I use any command with sudo the environment variables are not there. For example after setting HTTP_PROXY the command wget works fine without sudo

6条回答
  •  暖寄归人
    2020-11-22 02:27

    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"
    

提交回复
热议问题