0

This question already has an answer here:

In order to get the apt-get update/upgrade/install commands to work, I have added proxy information to my /etc/environment file. For example:

http_proxy="http://proxy-chain.acmewidgets.com:8080/"   
https_proxy="https://proxy-chain.acmewidgets.com:8080/"    
ftp_proxy="ftp://proxy-chain.acmewidgets.com:8080/"    
socks_proxy="socks://proxy-chain.acmewidgets.com:8080/"

Then, and this is important for my setup (not sure why - that is my question), I have to enter super user mode in order to get apt-get to work. Like I said, I'm not sure why, but simply prefacing the aforementioned apt-get commands with sudo does not work for me. For example, when I do sudo apt-get update, the terminal window hangs like so:

somedude@ACME-WIDGETS-03:~$ sudo apt-get update

0% [Connecting to us.archive.ubuntu.com (91.189.91.13)] [Connecting to security

What works is entering sudo su at the command line and then running the apt-get commands WITHOUT prefacing with sudo. I have to do this even if I am working in a super user terminal (opened by executing sudo gnome-terminal). Until I issue that sudo su command at the prompt, the proxy settings in /etc/environment are not seen. I checked this by doing echo $http_proxy before and after the su; before: nothing came back, after: what was set in /etc/environment came back.

Not a big deal, because I am able to get my updates and do my installations; but the idea with Ubuntu is to use sudo so that you don't do damage accidentally while in super user mode. So what is going on do you think? Thanks.

marked as duplicate by muru, Eliah Kagan, Alaa Ali, Tim, Eric Carvalho Aug 31 '14 at 0:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Tried setting proxy in /etc/apt/apt.conf askubuntu.com/questions/257290/configure-proxy-for-apt? – muru Aug 19 '14 at 20:23
  • 1
    UPDATE: What also works is "sudo -E apt-get update". The "-E" option preserves the existing environment variables. Between Ubuntu 14.04 (sorry, I should have mentioned before that I am running 14.04) and 13.10, has the default behavior for sudo been changed in this regard? – BillyBarty Aug 19 '14 at 20:30
  • FWIW, this looks like two questions in one. What do you want to do? If you want to preserve the environment while running sudo, then -E does exactly that. sudo -i -u root (so you start a login session as that user) would be my next choice. If what you want is for apt-get to use a proxy as required by your network (note, orthogonal to sudo's handling of env variables) definitely my preferred option is just setting the proxies in the appropriate config file for apt-get as muru suggested. – roadmr Aug 19 '14 at 21:38
1

This is expected behaviour - sudo resets the environment by default. Starting a root shell with sudo su is one workaround. You can also modify the sudo behaviour (see the linked page).

Not the answer you're looking for? Browse other questions tagged or ask your own question.