proxy環境でgemをインストールする方法
企業内のPCなどではWebProxyが使われていてgemをインストールできない時がある。
>gem install sinatra ERROR: Could not find a valid gem 'sinatra' (>= 0) in any repository ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) Errno::ETIMEDOUT: A connection attempt failed because the connected party di d not properly respond after a period of time, or established connection failed because connected host has failed to respond. - connect(2) (http://rubygems.org/ latest_specs.4.8.gz)
そんなときは、以下のコマンドを実行するとgemが使えるようになることがある。
>set http_proxy=http://proxyのIPアドレス:ポート番号
再び実行
>gem install sinatra Fetching: rack-1.4.1.gem (100%) (...以下略)
うまくいきました。
別の方法として、引数として渡す方法もあるようなのでメモしておきます。
>gem install dbi --http-proxy http://proxyのIPアドレス:ポート番号
参考:Proxy経由でgemが動作しない(2) 参考:[Ruby] gem updateがエラーとなった場合の対応