1. 安裝 rebar3
二進制文件方式安裝
下載 rebar3 二進制文件。下載完成後執行以下命令:
#拷貝到 /usr/local/Cellar 目錄下
$ cp ./Desktop/rebar3 /usr/local/Cellar/
#改變權限
$ chmod 755 /usr/local/Cellar/rebar3
#創建快捷方式
$ ln -s /usr/local/Cellar/rebar3 /usr/local/bin/rebar3
#驗證
$ rebar3 version
#顯示版本號,成功
rebar 3.13.0 on Erlang/OTP 22 Erts 10.6.2
源代碼方式安裝(未驗證)
#下載源碼
$ git clone https://github.com/erlang/rebar3.git && cd rebar3
#編譯
$ ./bootstrap
#安裝並設置環境變量
$ ./rebar3 local install
#更新
$ rebar3 local upgrade
2. 使用 rebar3
-
新建項目命令
rebar3 new <模版> <項目名>
模版 說明 app 創建帶有監控樹的有狀態的單OTP應用項目 lib 創建一個OTP應用庫(無監控樹),對於將多個模塊組合在一起作爲單應用的項目很有用 release 創建一個準備發佈的分散結構的項目 escript 單應用項目的特殊形式,可以將其構建爲可運行腳本 plugin rebar3插件 示例:
$ rebar3 new app myapp ===> Writing myapp/src/myapp_app.erl ===> Writing myapp/src/myapp_sup.erl ===> Writing myapp/src/myapp.app.src ===> Writing myapp/rebar.config ===> Writing myapp/.gitignore ===> Writing myapp/LICENSE ===> Writing myapp/README.md
-
爲項目添加依賴包
依賴包在 rebar.config 文件中的 deps 鍵下列出{deps, [ # 添加依賴包 package {cowboy, "2.7.0"}, # 或者向下面這樣,爲了兼容之前的版本 alternatively, source {cowboy, {git, "git://github.com/ninenines/cowboy.git", {tag, "1.0.1"}}} ]}.
再在 /src/*.app.src 文件中添加所需要的依賴
{application, <APPNAME>, [{description, ""}, {vsn, "<APPVSN>"}, {registered, []}, {modules, []}, {applications, [ kernel ,stdlib ,cowboy #新添加的依賴包 ]}, {mod, {<APPNAME>_app, []}}, {env, []} ]}.
-
構建項目
rebar3 compile
-
構建&運行項目
rebar3 shell