How to use apt-get behind proxy server (Ubuntu/Debian)

mypapit debianIf you are a Debian-based GNU/Linux user, then you’re probably familiar with synaptic and apt-get to install application from software repositories. This post focussed on how to use apt-get/synaptic behind proxy server/firewall which under normal circumstances, you’re unable to use apt-get.

If you’re using Synaptic

Open up your Synaptic package manager (usually as root), go to Settings-> Preference -> Network. Enter your proxy server details like : username:password@proxyserver.net, and put the proxy server port (usually 8080).

If you’re using command-line apt-get

Edit your /etc/bash.bashrc file as root.

Put these line at the end of your /etc/bash.bashrc file :

export http_proxy=http://username:password@proxyserver.net:port/
export ftp_proxy=http://username:password@proxyserver.netport/

You can omit the username:password, if your proxy server has no password. That’s all for today! Happy apt-get-ing!

debian,ubuntu,knoppix, mepis, apt-get

73 Replies to “How to use apt-get behind proxy server (Ubuntu/Debian)”

  1. The notation that works is URL-encoding.
    So for this it means:
    http_proxy=http://alwin.a:a@123@proxy.inhouse.net:3333/
    http_proxy=http://alwin.a:a%40123@proxy.inhouse.net:3333/

    /T

  2. Hi,

    I have some problem with the password. My password already have ‘@’ character. So whenever I try to do an ap-get update after exporting the proxy it is showing the character after the @ symbol. For eg : I am giving export http_proxy=http://alwin.a:a@123@proxy.inhouse.net:3333/

    and during the update process it is returning Could not resolve ‘123@proxy.inhouse.net’

    How can I fix this other than changing the password..?

  3. Hii,

    My password have a special character.
    I have faced this problem.

    used this format [prabhakaran:1123@7@:80]

    –2011-09-13 18:18:41– http://google.com/
    Resolving 7″@… failed: Name or service not known.
    wget: unable to resolve host address `7″@’

    Help me pls

  4. shailendra….try this,it sure should work..

    gedit /etc/apt/apt.conf

    then add these two lines

    Acquire::http::Proxy “http://username:password@proxy ip adress:8080/”;

    Acquire::ftp::Proxy “http://username:password@proxy ip adress:8080/”;

    where you input the following
    username = name of your wireless connection
    password = password of the wireless connection
    proxy ip address = ip address of your proxy server
    8080 = its the default proxy port,DONT CHANGE THAT!

  5. I tried farid’s method and i am getting followinf error:
    Syntax error /etc/apt/apt.conf:4: Extra junk at end of file
    please help me out.I am a newbie and installed ubuntu 10.10 tomorrow only.
    Thanks

  6. I’ve seen this problem sometimes cropping up! One of the reasons this problem can occur is when your http_proxy variable is not set properly!
    The $http_proxy variable in your terminal overrides the http::proxy variable in /etc/apt/conf file and the connection is not established if the http_proxy variable in the terminal is set to [proxy]:[port] instead of http://[proxy]:[port]. To check this out do the following:
    Type: echo $http_proxy in the terminal
    If it is something like this: 10.1.1.30:8080, then type: http_proxy=”http://10.1.1.30:8080″ . (we’re just adding the ‘http://’ before the content of the variable)
    If the problem was because of the overriding variables, it’d be solved by now .. try typing sudo apt-get update and see if it works.

  7. just set them in /etc/apt/apt.conf

    like this:

    Acquire::http::proxy “http://user:pass@ip:port/”;
    Acquire::https::proxy “https://user:pass@ip:port/”;
    Acquire::ftp::proxy “ftp://user:pass@ip:port/”;

  8. None of the methods listed here worked for me; I keep getting the error: “407 Proxy Authentication Required”. Please help

  9. there is a lots of confusion proxy env variables. Some say put “export http_proxy=XXX” into /etc/profile , others say put it into /etc/bash.bashrc – now whats right, whats wrong ? Where to put them if you like to have a SYSTEM WIDE configuration ???

  10. Under gnome/ubuntu v7.04, I don’t have synaptics package manager or a settings/preferences/gnome path.

    Instead, appended the 2 exports (lowercase) to /etc/bash.bashrc and put my proxy info into the dialog box on System/Preferences/Network Proxy.

  11. Set the http_proxy environment variable, but most importantly, open Synaptics Package Manager, go to Settings->Preferences. Then click on the Network Tab. Enter your proxy information there and you’ll be rolling immediately.

  12. sir
    i dont know how to use proxy server, in internet explore i can set for proxy i.paddress and port but not working.
    another problem is that
    i can use same time , i.e mozila without proxy server, but with internet explore with proxy server

    plz reply me, this is , my first time question

    thanks

    sharma

  13. On Debian this is not working at all.
    No way to pass username and password correctly to apt.

    I’ve done everything, and i got ubuntu woking well many months ago.

    But debian… no way…

  14. i wonder… i read ALL your comments… but it did not work… they are all great… but they will not work if u have another set of IP Addresses on your laptop… other then the ones used in the network you are in…

    sometimes… i wonder hoe stupid i can be :D

    THANKS FOR ALL THE HELP… great blog

  15. The lower-case export lines with quotes worked for me:
    export http_proxy=”http://username:password@proxyserver.net:port”
    export ftp_proxy=”http://username:password@proxyserver.net:port”
    But I appended them to the file /etc/profile instead of /etc/bash.bashrc so that it would effect synaptic from the menus (and lots of other system programs).

  16. You can’t use the variable in uppercase (HTTP_PROXY) you have to use lowercase.
    The CLI tools do not recognize the uppercase environment var.

  17. Hi,
    I had the same problem and the export worked for me, but with quotes:
    export http_proxy=”http://username:password@proxyserver.net:port”
    export ftp_proxy=”http://username:password@proxyserver.net:port”

  18. after editing .bashrc file.I’m still getting the proxy authentication error message.plz get me out of this

  19. What if I want to use proxy for some website and don’t use proxy for some other websites? How to configure that?

  20. I have a password that ends with the character @ , how do get around the fact that there are 2 @@ in one line and prevent the failure of auth because of this.

  21. Yeah, Bill if you want to use apt without storing a password you can do this:-

    Add the following to /etc/bash.bashrc

    function proxy(){
    echo -n “username:”
    read -e username
    echo -n “password:”
    read -es password
    export http_proxy=”http://$username:$password@proxyserver:8080/”
    export ftp_proxy=”http://$username:$password@proxyserver:8080/”
    echo -e “\nProxy environment variable set.”
    }

    Then whenever you want to set the proxy variable you just type “proxy” at the command line. When prompted for your proxyserver user name you type it in (you may need to type domain\\user if it’s a domain account) and then when prompted type your password (which isn’t echoed to the screen).

    This will then set the environment variables, and they’ll be lost when you exit your session.

    Cheers,
    Al.

  22. Hello all,

    The problem with the solutions above is that a password is stored in a text file or in the Synaptic configuration. This is not acceptable to the IT staff where I work and really is the only reason I do not use Debian or Ubuntu at work.

    Is there a more secure solution, perhaps a way to get a secure dialog box which asks for proxy username and password each time Synaptic is used? Similar to the web browser?

    Thanks,
    Bill Chivers

  23. I think it is advisable to always declare shell environmental variables in all caps.

    export HTTP_PROXY=….
    export FTP_PROXY=…

    Cheers

    –arky

  24. Pingback: Viper2110
  25. Pingback: mario carri?n

Comments are closed.