DEV Community 👩‍💻👨‍💻

Cover image for Setup Network Proxy in Ubuntu Terminal
Tushar Rao
Tushar Rao

Posted on

Setup Network Proxy in Ubuntu Terminal

Not able to update/install any package using apt-get in Debian/Ubuntu. Accessing network in terminal when internet is configured with a proxy is troublesome sometimes.

Image-showing-error-in-the terminal

As you can see in the above image, it just keeps on connecting until the server is timed out.

Below is the easiest way to setup a proxy for your network to access internet in terminal with no hassle.

User need to set the proxy for apt-get. To set the proxy for apt-get, edit the file /etc/apt/apt.conf.

We use this acquire command to setup proxy for both http and https int the below format.

Acquire::http::Proxy "http://proxy:port";
Acquire::https::Proxy "https://proxy:port";
Acquire::ftp::Proxy "ftp://proxy:port";
Enter fullscreen mode Exit fullscreen mode

Note: Sometimes your OS requries authentication before setting up proxy for the network. For that use the below format,

Acquire::http::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
Acquire::https::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
Enter fullscreen mode Exit fullscreen mode

The username and password are your laptops/PC's login username and password.

Steps to follow:

  • To define proxy settings for apt, create or edit (if it already exists) a file named apt.conf in /etc/apt directory:
sudo nano /etc/apt/apt.conf
Enter fullscreen mode Exit fullscreen mode
  • Add the following lines to the file: For eg,
Acquire::http::Proxy "http://127.0.0.1:8080";
Acquire::https::Proxy "http://127.0.0.1:8080";
Enter fullscreen mode Exit fullscreen mode

Note: Here, replace these proxy and port values from your network proxy.

  • Save the file by pressing Ctrl + X and then hit Enter!

  • Now Source the file to update the changes in terminal.

source /etc/apt/apt.conf
Enter fullscreen mode Exit fullscreen mode
  • That's it! Now try to run the below command.
sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Internet-working-in-Terminal

Hope it helps you guys!. Thanks for supporting.
I have posted a video explanation on Youtube. Do check it out!

Top comments (1)

Collapse
 
wendydavis profile image
WendyDavis

I read your blog article. It has very useful information here. thanks!
Fast love spells with women clothing

🌚 Friends don't let friends browse without dark mode.

Just kidding, it's a personal preference. But you can change your theme, font, etc. in your settings.

The more you know. 🌈