apt-get not working behind restricted internet access
Solution 1
Do you have a proxy at your company? If so, you can set the proxy before running the apt-get update logged in as root first:
export http_proxy=http://host:port
apt-get update
Using sudo:
sudo http_proxy=http://host:port apt-get update
If your proxy requires authentication, you can set it in the URL (beware that the password will be saved in history as plain text):
http://username:password@host:port
Solution 2
The permanent method to set the apt-get proxy are as follows:
Modifying the
apt.conf
file. Edit the/etc/apt/apt.conf
or create a new file under/etc/apt/apt.conf.d/
with the following content:Acquire::http::Proxy "http://user:password@proxyiporhost:port"; Acquire::https::Proxy "http://user:password@proxyiporhost:port"; Acquire::ftp::Proxy "http://user:password@proxyiporhost:port";
Calling
apt-get
with the--options
/-o
switch. This method allows you to determine the proxy at run time, giving you the ability of an adhoc proxy:sudo apt-get -o Acquire::http::Proxy=http://user:password@proxyiporhost:port update
You can get as many
-o
you need.Using a configuration file. This is a mix between each of previous methods since it won't be a permanent that you have to modify each time you change networks and you can switch on/off as you see fit. For that we will need the
-c
option. We only need to create a file with the content like the first method and tell apt-get to read it with the switch:sudo apt-get -c proxy.conf update
Related videos on Youtube
Braiam
Updated on September 18, 2022Comments
-
Braiam over 1 year
I have boxes running in a company but they have internet browsing and firewalls for security.
When I do apt-get update or install it fails. But I have a remote server which ip is only allowed to have access.
How can I tell apt-get to go to my cloud server and via the cloud server get the packages downloaded or updated?
-
Admin over 10 yearsIf you use a proxy take a look at the answer from Hugo. There is more information here
-
Admin over 10 years@WarrenHill that wiki is misinforming, I've never seen apt-get use users environment variables to set the proxy. The only environment variable apt-get will ever use is
APT_CONFIG
. -
Admin over 10 years@Braiam I don't use a proxy so I'm not in a position to test but I've sent a lot of users to that page in the past and most of them have reported that it fixed their problems. Also the OP has accepted the answer so it presumably worked for them.
-
Admin over 10 years@WarrenHill he has another problem with VNC since in an edit he describe the problem. Accepting Hugo's answer seems that has nothing to do.
-
Admin over 10 years@yumyumyum I think you are experienced enough to know that answers should be below, not up your question. I rolled back the changes, please post your answer below.
-
-
Braiam over 10 yearsI would say that the first code block should be used if you are logged as root. If you add
sudo su
orsudo -i
or however you like to login as root, would be the best.