CentOS 8 安装 Erlang 和 Rebar3 指南
1. 准备工作:更新系统并安装依赖
sudo dnf update -y
sudo dnf install -y epel-release
sudo dnf groupinstall "Development Tools" -y
sudo dnf install -y openssl-devel ncurses-devel autoconf git
2. 安装 Erlang(推荐源码编译)
方法一:源码编译安装(最新版)
# 下载源码(以25.3为例)
wget https://github.com/erlang/otp/releases/download/OTP-25.3/otp_src_25.3.tar.gz
tar -zxvf otp_src_25.3.tar.gz
cd otp_src_25.3# 配置编译
./configure
make
sudo make install
方法二:通过仓库安装(版本可能较旧)
sudo dnf install -y erlang
3. 验证 Erlang 安装
erl
出现 Erlang shell 即成功(按 Ctrl+C
两次退出):
Erlang/OTP 25 [erts-13.2] [source] [64-bit]Eshell V13.2 (abort with ^G)
1>
4. 安装 Rebar3
# 下载二进制文件
wget https://s3.amazonaws.com/rebar3/rebar3
chmod +x rebar3
sudo mv rebar3 /usr/local/bin/# 验证安装
rebar3 --version
输出示例:rebar 3.22.1 on Erlang/OTP 25
5. 备选方案:源码编译 Rebar3
git clone https://github.com/erlang/rebar3.git
cd rebar3
./bootstrap
sudo cp rebar3 /usr/local/bin/
常见问题解决
- 依赖缺失错误:
确保已安装所有依赖:
sudo dnf install -y gcc-c++ glibc-devel make m4 perl
- OpenSSL 兼容问题:
编译 Erlang 时指定 OpenSSL 路径:
./configure --with-ssl=/usr/include/openssl
- 版本冲突:
若已安装旧版 Erlang,先卸载:
sudo dnf remove erlang*
验证环境
创建测试项目:
mkdir test_project && cd test_project
rebar3 new app myapp
cd myapp
rebar3 compile
输出 ===> Compiling myapp
即表示环境配置成功。
提示:
- 源码编译可获得最新特性,仓库安装更快捷
- 生产环境建议使用版本管理工具(如
asdf
)- 完整文档参考:Erlang Docs,Rebar3 Docs