1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rubygems.org にアクセスできず、 serverspec がインストールできない

Last updated at Posted at 2022-07-03

環境

  • Windows 10
  • VirtualBox
  • ubuntu/focal64 (virtualbox, 20220308.0.0)
  • ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu
  • gem 3.1.2
  • Cisco Any Connect

発生した現象

Windows 10 上で動作する VirtualBox 上で Ubuntu 20.04 LTS をホストした。

gem install serverspec

のコマンドを実行したところ、以下のようなエラーが出て serverspec のインストールが失敗した。

default: ERROR:  Could not find a valid gem 'serverspec' (>= 0), here is why:
default: Unable to download data from https://rubygems.org/ - timed out (https://rubygems.org/specs.4.8.gz)

Cisco Any Connect を用いて、宅内とは異なる別のネットワークと VPN を接続した状態での実行だった。

VPN を接続した状態では、ブラウザから rubygems.org へのアクセスもエラーが発生しできなかった。

VPN を切断した状態ではブラウザから rubygems.org へのアクセスはできたが、依然、 VirtualBox 上の Ubuntu 環境からのアクセスはできないままだった。

解決方法

VPN を切断した状態で、Windows 10 上に gem を全てダウンロードした。

それを Ubuntu 環境にアップロードし、ローカルでのインストールを行った。

まず Gemfile を作成。

cat <<'EOF' > Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
gem "serverspec"
EOF

Windows 10 上で bundle install を実行する。

同じ階層に vendor/cache ディレクトリが作成され、その中に依存するものも含め serverspec に関する全ての gem ファイルがダウンロードされる。

ruby - What is the simplest way to download a gem without installing rubygems? - Super User

bundle install

これを VirtualBox 環境にアップロードする。今回は synced_folder の設定を利用していたため、そのディレクトリにコピーするだけでよい。

Ubuntu にログイン、コピーしたディレクトリ階層に移動し、 gem install --local serverspec を実行する

$ sudo gem install --local serverspec
Successfully installed sfl-2.3
... (略
Installing ri documentation for serverspec-2.42.0
Done installing documentation for sfl, net-ssh, net-scp, specinfra, multi_json, diff-lcs, rspec-support, rspec-expectations, rspec-core, rspec-its, rspec-mocks, rspec, serverspec after 9 seconds
13 gems installed

これで、 serverspec の gem ファイルをダウンロードすることができた。

余談

本件については Stack Overflow などで様々な解決方法が議論・提案されていたが、結局自分の環境でうまくいく方法を見つけることはできなかった。

これは暫定対応なので、恒久対応を今後見つける必要がある。引き続き調査する予定。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?