Once again I bumped into a proxy issue, but now I’m inside a *nix environment.
I recently installed an Ubuntu 12.04.3 LTS server inside a virtual box, primarily to be used as a web server for my GitLab repo management. I was following this installation guide when suddenly in step 2, I encountered an error, something like this:
curl: (7) couldn't connect to host
Curl couldn’t seem to connect and download the ruby-2.0.0-p247.tar.gz file. Well since I thought this is just an isolated case, I opted to manually download the file and untar it. This is all fine with me until I encountered the next error:
ERROR: Could not find a valid gem 'bundler' (>=0), here is why: Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT:: Connect timed out - connect(2) (https://rubygems.org/latest_specs.4.8.gz)
This is just annoying because I know very much that this is a proxy issue. I’ve encountered this in the windows environment and I managed to fix it, as elaborated in this post. But inside ubuntu, much more a server, without any GUI (definitely not my cup of tea), I braced myself for a daunting task. Good thing, through hours of research, these valuable info popped out and saved me from spending precious time troubleshooting stuff.
- http://askubuntu.com/questions/175172/how-do-i-configure-proxies-in-ubuntu-server-or-minimal-cli-ubuntu
- http://askubuntu.com/questions/158557/setting-proxy-from-terminal
Below is the gist of the links above (credits to Baltusaj, geirha, Julian Knight, izx and the others involved in the discussion).
WAYS TO IMPLEMENT THE PROXY
>> ONE-AND-DONE USAGE
If you need to access the internet but you don’t want your proxy getting saved on a configuration file, you can do this:
sudo env http_proxy=http://<user>:<password>@<server>:<port> apt-get update
The magic command is the env http_proxy because this will carry your credentials to be able to pass through the wall.
>> THROUGH CONFIGURATION FILES
If you think you’d need to go back and forth through the firewall, typing the commands mentioned in the previous point would be a hassle. Below are the options:
:: Through the environment configuration file
This is the setup that worked for me.
- Open /etc/environment file
- Add the ff. variable-value pairs (enter both upper and lower case variables since applications only look for one or the other:
-
http_proxy="http://<server>:<port>"
-
HTTP_PROXY="http://<server>:<port>"
-
https_proxy="http://<server>:<port>"
-
HTTPS_PROXY="http://<server>:<port>"
-
ftp_proxy="http://<server>:<port>"
-
FTP_PROXY="http://<server>:<port>"
-
no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
-
NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
-
- Save it and you’re done
:: Through the 95proxies configuration file
According to izx of askubuntu.com, In some cases, apt-get, aptitude, etc. will not obey the environment variables when used normally with sudo. Configure them separately inside this file.
- Open /etc/apt/apt.conf.d/ directory
- If the 95proxies file does not exist, make one
- Add the ff. variable-value pairs:
-
Acquire::http::proxy "http://<server>:<port>";
-
Acquire::https::proxy "https://<server>:<port>";
-
Acquire::ftp::proxy "ftp://<server>:<port>";
-
- Save it and you’re done
DON’T FORGET TO RESTART YOUR SERVER.
Enjoy!