[Erlang36]kerl轻松管理安装各种OTP版本

kerl只有一个目标:让我们在不同的OTP版本间随意切换。他是一个纯Bash项目。简单实用的工作利器!

Readme里面用法已说明得非常清楚了。建议按流程来一次。

1.下载

安装(一个bash脚本,根本就不用安装~)

 curl -O https://raw.githubusercontent.com/kerl/kerl/master/kerl&chmod a+x kerl

2.工作原理

official Erlang website上得到所有的release包信息,然后再下载对应的release后安装到指定的目录下。你也可以使用KERL_BUILD_BACKEND=git

指定从official source code上下载源.

3.用法

./kerl
kerl: build and install Erlang/OTP
usage: ./kerl <command> [options ...]

  <command>       Command to be executed

Valid commands are:
  build    Build specified release or git repository
  install  Install the specified release at the given location
  deploy   Deploy the specified installation to the given host and location
  update   Update the list of available releases from your source provider
  list     List releases, builds and installations
  delete   Delete builds and installations
  active   Print the path of the active installation
  plt      Print Dialyzer PLT path for the active installation
  status   Print available builds and installations
  prompt   Print a string suitable for insertion in prompt
  cleanup  Remove compilation artifacts (use after installation)
  version  Print current version (current: 1.3.2)

3.1 列出所有可用的release包

$ ./kerl list releases
R10B-0 R10B-10 R10B-1a R10B-2 R10B-3 R10B-4 R10B-5 R10B-6 R10B-7 R10B-8 R10B-9 R11B-0 R11B-1 R11B-2 R11B-3 R11B-4 R11B-5 R12B-0 R12B-1 R12B-2 R12B-3 R12B-4 R12B-5 R13A R13B01 R13B02-1 R13B02 R13B03 R13B04 R13B R14A R14B01 R14B02 R14B03 R14B04 R14B R14B_erts-5.8.1.1 R15B01 R15B02 R15B02_with_MSVCR100_installer_fix R15B03-1 R15B03 R15B R16A_RELEASE_CANDIDATE R16B01 R16B02 R16B03-1 R16B03 R16B 17.0-rc1 17.0-rc2 17.0 17.1 17.3 17.4 17.5 18.0 18.1 18.2 18.2.1 18.3 19.0
Run './kerl update releases' to update this list from erlang.org

3.2 下载指定release包并编译

KERL_CONFIGURE_OPTIONS=--enable-hipe ./kerl build 19.0 19.0_hipe % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 184 100 184 0 0 132 0 0:00:01 0:00:01 --:--:-- 132 0 64.8M 0 51751 0 0 4277 0 4:25:04 0:00:12 4:24:52 10189

要从官网上下70M的东西,erlang.org对中国区本来就慢,建议使用git源(KERL_BUILD_BACKEND=git)

3.3 查看现在有release包列表

./kerl list builds
17.4 17.4
19.0 19.0_hipe

3.4 安装包

$./kerl install 19.0_hipe /usr/local/sbin/erl_19_0_hipe
Installing Erlang/OTP 19.0 (19.0) in /usr/local/sbin/erl_19_0...
You can activate this installation running the following command:
. /usr/local/sbin/erl_19_0/activate
Later on, you can leave the installation typing:
kerl_deactivate

稍等一会,就会提示你安装成功。

3.5 使用指定版本的OTP

如果想在当前的shell中使用安装好的上面19版本的OTP,只需要

$./usr/local/sbin/erl_19_0/activate

然后打开erlang shell试试看:

$erl
Erlang/OTP 19 [erts-8.0] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
Eshell V8.0  (abort with ^G)
1>

成功在当前的shell中使用19的release啦。

如果不想使用了,也可以使用下面命令来禁用

kerl_deactivate

以上就是kerl的基本用法,有了它,你就可以在本机上装多个版本的erlang了。对要测试多个版本的工作太有用了。

4. 补充

可能有人也注意到了,这是从源码重新编译,可不可以更加方便的指定编译的参数,

而不是像上面在命令行中 KERL_CONFIGURE_OPTIONS=--enable-hipe。

 这是可以的。

kerl在home下有一个.kerlrc(类似于.bashrc),比如我的

emacs ~/.kerlrc
KERL_CONFIGURE_OPTIONS="--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll  --enable-darwin-64bit --with-ssl=/usr/local/Cellar/openssl/1.0.2h_1"

除了这个configure options外,还有很多项都可以在.kerlrc中配置(可以在readme中找到详细的说明),方便又不缺乏灵活。

kerl在home下有一个.kerl(类似于.ssh目录)

cd ~/.kerl && ls
archives          builds            otp_builds        otp_builds-e      otp_installations otp_releases

这里就是kerl命令存放release和存install数据的地方。

5. 资源

5.1 elixir也有对应的项目叫kiex

5.2 kerl甚至可以deploy到远程的服务器上安装,只要你配置好ssh key,虽然没有用到,但是这也太炫酷啦。

5.3 basho使用kerl安装的文档:http://docs.basho.com/riak/kv/2.1.4/setup/installing/source/erlang/#kerl-prerequisites

 If my fingers were erlang processes~

posted @ 2016-09-07 00:19  写着写着就懂了  阅读(4049)  评论(0编辑  收藏  举报