Apt loads all configuration files under /etc/apt/apt.conf.d. You can create a configuration specifically for our proxy there, keeping it separate from all other configurations.
- Create a new configuration file named proxy.conf.
sudo touch /etc/apt/apt.conf.d/proxy.conf
- Open the proxy.conf file in a text editor.
sudo vi /etc/apt/apt.conf.d/proxy.conf
- Add the following line to set your HTTP proxy.
Acquire::http::Proxy "http://proxy.server:port/";
- Add the following line to set your HTTPS proxy.
Acquire::https::Proxy "http://proxy.server:port/";
- Save your changes and exit the text editor.
Your proxy settings will be applied the next time you run Apt.
NOTE : If this is CentOS 8 or above use this:
Dnf repositories (“repos”) can be accessed through standard proxy servers such as Squid or any other proxy server configured by your system administrator. You need to configure the proxy server in /etc/dnf/dnf.conf file as follows:
proxy=http://URL:PORT/ – Proxy serer URL to the proxy server that yum should use. You must set a complete URL, including the TCP port number. If your corporate proxy server requires a username and password, specify these by adding following two settings in dnf.conf file.