Apt can take the system environment values of the http_proxy as well as https_proxy defined.
So to get over this set the proxies as the user environment variables or system environment variables, which will be automatically used by apt actions
So set env variables related to the http_proxy or https_proxy these in either of the following as
~/.profile
~/.bash_profile
~/.bashrc
or
If this has to be set as the system Env variables, these can be set in the file as
/etc/profile
or
/etc/environment
or in a file in the
/etc/profile.d
like /etc/profile.d/more_env_variables.sh
The entries for the proxy are as
export http_proxy=http://<Proxy Server FQDN or IP:<Port>
export https_proxy=http://<Proxy Server FQDN or IP>:<Port>
export no_proxy=<IP1|FQDN1| ...>
export https_proxy=http://<Proxy Server FQDN or IP>:<Port>
export no_proxy=<IP1|FQDN1| ...>
To be noted that as these files are executed at the time of login the user may have to logoff and logback in or can execute the Profile Variable files as
. /bash_profile
please note the [SPACE] after the dot '.' .
Alternative way is that if there is a particular proxy set for APT or you just want the proxy server to be reached by APT then you can specify the proxy server in /etc/apt/apt.conf
Or depending on the Ubuntu distribution version you can create a file under /etc/apt/apt.conf.d
to have the contents like this
Acquire::http::proxy "http://<Proxy_server_FQDN_or_IP>:<PORT>
Acquire::https::proxy "http://<Proxy_server_FQDN_or_IP<:<PORT>
Replace the values above with the Proxy server IP and Port being used at your network.
An Alternative way if you do not want the proxy settings to be saved persistently just want to be available for the current session then, simply export the env variables as below
export http_proxy=http://<Proxy_server_FQDN_or_IP>:<PORT>
export https_proxy=http://<Proxy_server_FQDN_or_IP>:<PORT>