http_proxy="http://username:password@host:port"
export http_proxy
To maintain this environment variable when using the sudo command do the following:
sudo visudo
Add this lines to the end of the file:
Defaults env_reset
Defaults env_keep = "http_proxy"
Save and exit and that's all.