LoginSignup
8
6

More than 3 years have passed since last update.

Elixir の Hex を中国から使う方法

Last updated at Posted at 2015-12-23

Elixir のパッケージ管理ツール Hex はデフォルト設定のままでは、中国から利用できません。これは、Hex のデフォルト cdn_url が Amazon S3 の北米リージョンに設定されており、GFW によりブロックされているからです1 2。そこで cdn_url を Amazon S3 シンガポール・リージョンにあるミラーサイトに変更します。

Hex のインストール

mix local.hex コマンドは、以下のように失敗します。(同様に mix deps.get も失敗します)

$ mix local.hex

16:09:54.236 [error] Failed updating session: 
   ProfileName: :httpc_mix
   SessionId:   {{'s3.amazonaws.com', 443}, #PID<0.78.0>}
   Pos:         7
   Value:       0

...(中略)...

16:09:54.656 [error] GenServer #PID<0.78.0> terminating

...(中略)...

Could not fetch archive at:

    https://s3.amazonaws.com/s3.hex.pm/installs/1.1.0/hex-0.9.0.ez

Please download the archive above manually to your current directory and run:

    mix archive.install ./hex-0.9.0.ez

もし運良くインストールできたなら、次のステップ(Hex の cdn_url を変更する)に進みます。

もしダメなら、シンガポール・リージョンにあるミラーサイトからパッケージをダウンロードして、エラーメッセージに書かれていた通り mix archive.install でインストールします。

Hex のバージョン部分 0.9.0 は、エラーメッセージを元に書き換えてください。

$ curl -O https://s3-ap-southeast-1.amazonaws.com/s3-asia.hex.pm/installs/1.1.0/hex-0.9.0.ez 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  274k  100  274k    0     0  32570      0  0:00:08  0:00:08 --:--:-- 48767

$ mix archive.install ./hex-0.9.0.ez
Are you sure you want to install archive "./hex-0.9.0.ez"? [Yn] 
* creating /home/tatsuya/.mix/archives/hex-0.9.0.ez
$

Hex の cdn_url を変更する

Hex の cdn_url を、Amazon S3 シンガポール・リージョン(ap-southeast-1)にある、ミラーサイトへ変更します。

$ mix hex.config cdn_url https://s3-ap-southeast-1.amazonaws.com/s3-asia.hex.pm
Registry update failed (http_error)
{:failed_connect, [{:to_address, {'s3.amazonaws.com', 443}}, {:inet, [:inet], :etimedout}]}
cdn_url: "https://s3-ap-southeast-1.amazonaws.com/s3-asia.hex.pm"

ただ、これも最初に s3.amazonaws.com にアクセスしようとするみたいで、かなり待たされます。もしダメな時は、Ctrl + C, A でアボートして、hex.config を以下のように書き換えるといいでしょう。

$ cat ~/.hex/hex.config 
{cdn_url,<<"https://s3-ap-southeast-1.amazonaws.com/s3-asia.hex.pm">>}.

使えるかどうか試してみる

$ mix hex.info        
Hex v0.9.0

Registry file available (last updated: 2015-12-23 08:52:57)
Size: 918kB
Packages #: 999
Versions #: 4440

$ mix hex.search ex_doc
ex_doc
ex_doc_dash
ex_doc_epub
ex_dockerapi

大丈夫なようです。

参考


  1. 2015年12月現在の状況。s3.amazonaws.com は、少なくてもこの2年間はブロックされています。 

  2. http://www.greatfirewallofchina.org/ では、中国国外にいる時に、中国からのアクセスがブロックされているかどうかテストできます。(中国国内からはアクセス不可) 

8
6
2

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
8
6