How do I run apt-get when Im behind a proxy ?

In order configure your Ubuntu/Debian box to access HTTP, HTTPS and FTP via a Proxy you will need to assign some environment variables.

Assign Environmental Variables

Below shows you the different variables you need to declare :

export HTTP_PROXY=[PROXY IP]:[PORT]
export HTTPS_PROXY=[PROXY IP]:[PORT]
export FTP_PROXY=[PROXY IP]:[PORT]

Survive reboot

To survive a reboot you need to add these to /etc/bash.bashrc

echo export HTTP_PROXY=http://[PROXY IP]:[PORT] >> /etc/bash.bashrc
echo export HTTPS_PROXY=https://[PROXY IP]:[PORT] >> /etc/bash.bashrc
echo export FTP_PROXY=ftp://[PROXY IP]:[PORT] >> /etc/bash.bashrc

User Authentication

Below is an example if you need to add authentication credentials:

HTTP_PROXY=http://[USERNAME]:[PASSWORD]@[PROXY IP]:[PORT]
Rick Donato

Want to become a Linux expert?

Here is our hand-picked selection of the best courses you can find online:
Linux Mastery course
Linux Administration Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial