安裝以前,先看一下它們的簡要說明html
Erlang是一種開源編程語言,用於構建對高可用性有要求的大規模可擴展的軟實時系統。它一般用於電信,銀行,電子商務,計算機電話和即時消息中。Erlang的runtime系統具備對併發,分發和容錯的內置支持。它是在愛立信計算機科學實驗室設計的。java
Elixir是一種動態的功能語言,旨在用於構建可伸縮和可維護的應用程序。Elixir利用了以運行低延遲,分佈式和容錯系統而著稱的Erlang VM,同時也成功地用於Web開發和嵌入式軟件領域。c++
如今開始在CentOS 7.7 64位服務器中安裝Erlang和Elixir。git
安裝Erlang和Elixir以前,須要安裝如下依賴。github
yum updateyum install epel-releaseshell
yum install gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf java-1.8.0-openjdk-devel git wget wxBase.x86_64編程
因爲官方存儲庫中的Erlang版本可能比較舊,這裏我將下載並安裝最新的Erlang版本。bootstrap
添加Erlang官方存儲庫以安裝最新的Erlang。windows
首先到Erlang存儲庫頁面,根據你使用的發行版下載存儲庫:bash
因爲如今在CentOS 7.7中安裝Erlang,所以我將添加如下存儲庫。
wget http://packages.erlang-soluti...
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
使用如下命令更新存儲庫列表:
yum update
使用如下命令安裝erlang
yum install erlang
如今最新版本的Erlang已安裝完成。
運行如下命令以驗證是否已安裝Erlang。
erl
輸出示例:
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe] Eshell V10.6 (abort with ^G) 1>
若是看到如上的Erlang shell,表示安裝成功!要關閉shell,只需按兩次 Ctrl-C。
建立一個名爲「 hello.erl」的新文件。
vi hello.erl
添加如下代碼:
-module(hello). -export([hello_world/0]). hello_world() -> io:fwrite("hello, world\n").
:wq
保存並關閉文件。
使用如下命令打開Erlang shell:
erl
運行如下命令,切記在每一個命令的末尾添加英文點:
c(hello).hello:hello_world().
輸出示例:
[root@localhost ~]# erl Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe] Eshell V10.6 (abort with ^G) 1> c(hello). {ok,hello} 2> hello:hello_world(). hello, world ok 3>
安裝Elixir以前必需要先安裝Erlang!
Elixir在EPEL存儲庫中可用,但已通過時了。爲了安裝最新版本,這裏使用源碼編譯安裝。
如今將Elixir從GitHub拉取到本地:
git clone -b v1.9.4 https://github.com/elixir-lan...
上面的命令會將最新版本拉取到當前工做目錄中名爲 elixir
的文件夾中。
注意:最好指定版本,否則的話你安裝完查看版本,可能就是以下所示同樣,源碼和版本號不匹配
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe] Elixir 1.10.0-dev (ee758f9) (compiled with Erlang/OTP 22)
接下來進到 elixir
目錄:
cd elixir/
運行如下命令開始編譯Elixir:
make clean test
輸出示例:
[root@localhost elixir]# make clean test rm -rf ebin rm -rf lib/*/ebin rm -rf lib/elixir/src/elixir_parser.erl make[1]: 進入目錄「/root/elixir」 rm -rf lib/*/_build/ rm -rf lib/*/tmp/ rm -rf lib/elixir/test/ebin/ rm -rf lib/mix/test/fixtures/deps_on_git_repo/ rm -rf lib/mix/test/fixtures/git_rebar/ rm -rf lib/mix/test/fixtures/git_repo/ rm -rf lib/mix/test/fixtures/git_sparse_repo/ rm -f erl_crash.dump make[2]: 進入目錄「/root/elixir」 rm -f man/elixir.1 rm -f man/elixir.1.bak rm -f man/iex.1 rm -f man/iex.1.bak make[2]: 離開目錄「/root/elixir」 make[1]: 離開目錄「/root/elixir」 Recompile: src/elixir_utils Recompile: src/elixir_tokenizer Recompile: src/elixir_sup Recompile: src/elixir_rewrite Recompile: src/elixir_quote Recompile: src/elixir_parser Recompile: src/elixir_overridable Recompile: src/elixir_module Recompile: src/elixir_map Recompile: src/elixir_locals Recompile: src/elixir_lexical Recompile: src/elixir_interpolation Recompile: src/elixir_import Recompile: src/elixir_fn Recompile: src/elixir_expand Recompile: src/elixir_errors Recompile: src/elixir_erl_var Recompile: src/elixir_erl_try Recompile: src/elixir_erl_pass Recompile: src/elixir_erl_for Recompile: src/elixir_erl_compiler Recompile: src/elixir_erl_clauses Recompile: src/elixir_erl Recompile: src/elixir_env Recompile: src/elixir_dispatch Recompile: src/elixir_def Recompile: src/elixir_config Recompile: src/elixir_compiler Recompile: src/elixir_code_server Recompile: src/elixir_clauses Recompile: src/elixir_bootstrap Recompile: src/elixir_bitstring Recompile: src/elixir_aliases Recompile: src/elixir Generated elixir app ==> bootstrap (compile) Compiled lib/elixir/lib/kernel.ex Compiled lib/elixir/lib/macro/env.ex Compiled lib/elixir/lib/keyword.ex Compiled lib/elixir/lib/module.ex Compiled lib/elixir/lib/list.ex Compiled lib/elixir/lib/macro.ex Compiled lib/elixir/lib/kernel/typespec.ex Compiled lib/elixir/lib/code.ex Compiled lib/elixir/lib/code/identifier.ex Compiled lib/elixir/lib/module/checker.ex Compiled lib/elixir/lib/module/locals_tracker.ex Compiled lib/elixir/lib/module/parallel_checker.ex Compiled lib/elixir/lib/module/types/helpers.ex Compiled lib/elixir/lib/module/types/infer.ex Compiled lib/elixir/lib/module/types/expr.ex Compiled lib/elixir/lib/module/types/pattern.ex Compiled lib/elixir/lib/module/types.ex Compiled lib/elixir/lib/kernel/utils.ex Compiled lib/elixir/lib/exception.ex Compiled lib/elixir/lib/protocol.ex Compiled lib/elixir/lib/stream/reducers.ex Compiled lib/elixir/lib/enum.ex Compiled lib/elixir/lib/map.ex Compiled lib/elixir/lib/inspect/algebra.ex Compiled lib/elixir/lib/inspect.ex Compiled lib/elixir/lib/access.ex Compiled lib/elixir/lib/range.ex Compiled lib/elixir/lib/regex.ex Compiled lib/elixir/lib/string.ex Compiled lib/elixir/lib/string/chars.ex Compiled lib/elixir/lib/io.ex Compiled lib/elixir/lib/path.ex Compiled lib/elixir/lib/file.ex Compiled lib/elixir/lib/system.ex Compiled lib/elixir/lib/kernel/cli.ex Compiled lib/elixir/lib/kernel/error_handler.ex Compiled lib/elixir/lib/kernel/parallel_compiler.ex Compiled lib/elixir/lib/kernel/lexical_tracker.ex make[1]: 進入目錄「/root/elixir」 ==> unicode (compile) Compiling /root/elixir/lib/elixir/unicode/unicode.ex (it's taking more than 15s) make[1]: 離開目錄「/root/elixir」 ==> elixir (compile) Compiling /root/elixir/lib/elixir/lib/base.ex (it's taking more than 15s) make[1]: 進入目錄「/root/elixir」 Generated elixir app make[1]: 離開目錄「/root/elixir」 ==> eex (compile) ==> mix (compile) Generated mix app ==> ex_unit (compile) Generated ex_unit app ==> logger (compile) Generated logger app Generated eex app ==> iex (compile) Generated iex app ==> elixir (eunit) All 190 tests passed. ==> elixir (ex_unit) ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Finished in 81.6 seconds (47.2s on load, 34.4s on tests) 1569 doctests, 3374 tests, 0 failures, 7 excluded Randomized with seed 847643 ==> ex_unit (ex_unit) ............................................................................................................................................................................................................................................................................................................................................................... Finished in 6.2 seconds (3.9s on load, 2.3s on tests) 42 doctests, 309 tests, 0 failures Randomized with seed 541463 ==> logger (ex_unit) ............................................................................................................................ Finished in 2.4 seconds (1.9s on load, 0.4s on tests) 3 doctests, 121 tests, 0 failures Randomized with seed 211604 ==> mix (ex_unit) Excluding tags: [windows: true] ............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Finished in 158.5 seconds (12.1s on load, 146.4s on tests) 9 doctests, 611 tests, 0 failures Randomized with seed 334499 ==> eex (ex_unit) ........................................................................................... Finished in 0.5 seconds (0.4s on load, 0.06s on tests) 5 doctests, 86 tests, 0 failures Randomized with seed 599118 ==> iex (ex_unit) ....................................................................................................................................................................................................................................... Finished in 8.5 seconds (2.1s on load, 6.3s on tests) 231 tests, 0 failures Randomized with seed 207545 [root@localhost elixir]#
若是測試經過,則表示編譯安裝完成。
接下來將Elixir的bin路徑添加到PATH環境變量中,不然Elixir將沒法正常工做。
方法一(暫時生效)
如今運行如下命令:
export PATH="$PATH:/root/elixir/bin"
在這裏,我把Elixir安裝在了 /root/elixir/
。你必須將此路徑替換爲你實際的Elixir安裝路徑。
方法二(只對當前登錄用戶生效,永久生效)
vi ~/.bash_profile
默認以下:
PATH=$PATH:$HOME/bin
添加後:
PATH=$PATH:$HOME/bin:$PATH:/root/elixir/bin
接下來執行 source ~/.bash_profile
使其當即生效或者 reboot
重啓生效
方法三(對全部系統用戶生效,永久生效)
vi /etc/profile
在文件最後添加如下兩行:
PATH="$PATH:/root/elixir/bin" export PATH
接下來執行 source /etc/profile
使其當即生效或者 reboot
重啓生效
要驗證是否已安裝Elixir,請運行:
iex
輸出示例:
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe] Interactive Elixir (1.9.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)>
若是你看到Elixir shell,則表示安裝成功!
一樣,要關閉Elixir shell,只需按兩次Ctrl-C。
查看Elixir版本:
elixir --version
輸出示例:
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe] Elixir 1.10.0-dev (ee758f9) (compiled with Erlang/OTP 22)
如今CentOS 7.7服務器中已成功安裝並設置可工做的Erlang和Elixir開發環境,全部安裝已完成!
參考連接: