跳转至

在Linux(CentOS、Ubuntu等等)中安装Erlang和Elixir

检查旧版本

Bash
$ uname -a
Linux ws-ersyia-0 5.4.241-1-tlinux4-0017.10 #1 SMP Wed May 8 17:01:03 CST 2024 x86_64 x86_64 x86_64 GNU/Linux
Bash
1
2
3
4
$ elixir --version
Erlang/OTP 24 [erts-12.3.2.17] [source] [64-bit] [smp:8:2] [ds:8:2:10] [async-threads:1] [jit]

Elixir 1.13.3 (compiled with Erlang/OTP 22)

卸载旧版本

Bash
1
2
3
4
5
$ where elixir
/opt/elixir
$ where erl
/opt/erlang
$ rm -rf /opt/elixir /opt/erlang 

下载安装包

Bash
$ wget https://github.com/erlang/otp/releases/download/OTP-27.0.1/otp_src_27.0.1.tar.gz
$ wget https://github.com/elixir-lang/elixir/archive/refs/tags/v1.17.2.zip

安装 erlang

Bash
1
2
3
4
5
$ tar zxvf otp_src_27.0.1.tar.gz
$ cd otp_src_27.0.1 
$ ./configure && make && make install
$ erl -s erlang halt                                                      
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:2] [ds:8:2:10] [async-threads:1] [jit:ns]

安装 elixir

Bash
1
2
3
4
5
6
7
$ unzip v1.17.2.zip 
$ cd elixir-1.17.2 
$ make clean compile
$ ./bin/elixir --version
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:2] [ds:8:2:10] [async-threads:1] [jit:ns]

Elixir 1.17.2 (compiled with Erlang/OTP 27)

配置 PATH

Bash
$ vim ~/.zshrc

添加路径到PATH

Bash
export PATH=$PATH:/workspace/elixir-1.17.2/bin

如果要配置文件立即生效,还需要source一下配置文件

Bash
$ source ~/.zshrc

查看版本:

Bash
1
2
3
4
$ elixir --version
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:2] [ds:8:2:10] [async-threads:1] [jit:ns]

Elixir 1.17.2 (compiled with Erlang/OTP 27)

mix ok & install rebar3

配置mix hex和rebar3

Bash
$ mix local.hex -y
$ wget https://s3.amazonaws.com/rebar3/rebar3
$ chmod +x ./rebar3 
$ ./rebar3 local install

$ vim ~/.zshrc
export PATH=/root/.cache/rebar3/bin:$PATH

$ rebar3 -v           
rebar 3.23.0 on Erlang/OTP 27 Erts 15.0.1

如果要配置文件立即生效,还需要source一下配置文件

Bash
$ source ~/.zshrc