For package installation in the Proxy environment, it is necessary to designate the proxy server by environment variables and so on. Similarly for Gem and Bundler, setting of environment variables http_proxy is required.
During construction of the environment, due to misconfiguration Proxy did not work as expected, so we confirmed the difference in behavior depending on the setting contents.
- Validation environment
- (Failed) Proxy Not Set
- (Success) http_proxy environment variable setting
- (Failure) misconfiguration of no_proxy
- (Successful) Set no_proxy properly
- Conclusion - Gem, Bundle installation fails due to setting error in Proxy environment
Validation environment
In this verification, the latest Ruby Docker image as of April 28, 2018 was used.
root@8271fa172878:/test# cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" root@8271fa172878:/test# ruby -v ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] root@8271fa172878:/test# gem -v 2.7.6 root@8271fa172878:/test# bundle -v Bundler version 1.16.1 root@8271fa172878:/test# cat ./Gemfile source 'https://rubygems.org' gem 'haml'
(Failed) Proxy Not Set
In the case that name resolution by DNS for the Internet can not be performed in the Proxy environment, if Proxy environment variable is not set , naturally the Gem installation and Bundle installation fail as follows.
root@8271fa172878:/test# env | grep proxy root@8271fa172878:/test# gem install haml ERROR: Could not find a valid gem 'haml' (>= 0), here is why: Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/specs.4.8.gz) root@8271fa172878:/test# bundle install Fetching source index from https://rubygems.org/ Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ Could not fetch specs from https://rubygems.org/
(Success) http_proxy environment variable setting
If environment variable of http_proxy is properly set, it succeeds as follows.
root@8271fa172878:/test# export http_proxy=http://192.168.1.76:8080 root@8271fa172878:/test# env | grep proxy http_proxy=http://192.168.1.76:8080 root@8271fa172878:/test# bundle install Fetching gem metadata from https://rubygems.org/.... Using bundler 1.16.1 Using temple 0.8.0 Using tilt 2.0.8 Fetching haml 5.0.4 Installing haml 5.0.4 Bundle complete! 1 Gemfile dependency, 4 gems now installed. Bundled gems are installed into `/usr/local/bundle`
(Failure) misconfiguration of no_proxy
Even in the Proxy environment, intra direct access etc. no_proxy often used for not to proxy domain/IP address specification by environment variable.
In the case that failed this time, we set no_proxy recursively as export no_proxy=$no_proxy,localhost,127.0.0.1
assuming addition of the target domain.
root@8271fa172878:/test# gem uninstall haml root@8271fa172878:/test# export no_proxy=$no_proxy,localhost,127.0.0.1 root@8271fa172878:/test# env | grep proxy http_proxy=http://192.168.1.76:8080 no_proxy=,localhost,127.0.0.1 root@8271fa172878:/test# bundle install Fetching gem metadata from https://rubygems.org/.... Using bundler 1.16.1 Using temple 0.8.0 Using tilt 2.0.8 Fetching haml 5.0.4 Retrying download gem from https://rubygems.org/ due to error (2/4): Gem::RemoteFetcher::UnknownHostError no such name (https://rubygems.org/gems/haml-5.0.4.gem) Retrying download gem from https://rubygems.org/ due to error (3/4): Gem::RemoteFetcher::UnknownHostError no such name (https://rubygems.org/gems/haml-5.0.4.gem) Retrying download gem from https://rubygems.org/ due to error (4/4): Gem::RemoteFetcher::UnknownHostError no such name (https://rubygems.org/gems/haml-5.0.4.gem) Gem::RemoteFetcher::UnknownHostError: no such name (https://rubygems.org/gems/haml-5.0.4.gem) An error occurred while installing haml (5.0.4), and Bundler cannot continue. Make sure that `gem install haml -v '5.0.4'` succeeds before bundling. In Gemfile: haml root@8271fa172878:/test# gem install haml ERROR: Could not find a valid gem 'haml' (>= 0), here is why: Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/specs.4.8.gz)
Although confirmation of dependency by Bundler was successful, it failed with error of Gem::RemoteFetcher::UnknownHostError: no such name
when Gem package was acquired. Even if you trial Gem install individually, it will fail with a name resolution error as well.
The troublesome thing is that Bundler can read the proxy settings and operate, but Proxy does not work with Gem.
no_proxy Proxy is not set due to syntax error
The reason for the above is caused by a syntax error of no_proxy as it is exchanged here, in which case Gem Proxy is not set, and it becomes direct access and Gem installation fails.
(NG) no_proxy=,localhost,127.0.0.1 (OK) no_proxy=localhost,127.0.0.1
(Successful) Set no_proxy properly
By setting no_proxy appropriately, Gem installation becomes possible as expected as follows.
root@8271fa172878:/test# export no_proxy=localhost,127.0.0.1 root@8271fa172878:/test# env | grep proxy http_proxy=http://192.168.1.76:8080 no_proxy=localhost,127.0.0.1 root@8271fa172878:/test# bundle install Fetching gem metadata from https://rubygems.org/.... Using bundler 1.16.1 Using temple 0.8.0 Using tilt 2.0.8 Fetching haml 5.0.4 Installing haml 5.0.4 Bundle complete! 1 Gemfile dependency, 4 gems now installed. Bundled gems are installed into `/usr/local/bundle`
Conclusion - Gem, Bundle installation fails due to setting error in Proxy environment
It was confirmed that Gem installation fails in Proxy environment due to misconfiguration of no_proxy. I realized again that it is important to properly set the Proxy environment variable.