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


- Add the following lines to the file:
For eg,
Enter fullscreen mode Exit fullscreen mode

Acquire::http::Proxy "http://127.0.0.1:8080";
Acquire::https::Proxy "http://127.0.0.1:8080";


> 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.

Enter fullscreen mode Exit fullscreen mode

source /etc/apt/apt.conf


- That's it! Now try to run the below command.

Enter fullscreen mode Exit fullscreen mode

sudo apt-get update


![Internet-working-in-Terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eglvxrdwfrc6tqjx5psv.jpeg)

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


Enter fullscreen mode Exit fullscreen mode

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