更新时间:2023-01-09 10:03:20浏览次数:926+次
本文将向您展示如何在Ubuntu 22.04 LTS系统上安装和使用最新版本的Erlang/OTP。
简介
Erlang是一种由Ericsson OTP产品部门支持和维护的功能性、通用性、并发编程语言和垃圾收集运行时环境。
Erlang编程语言是为并发、容错和分布式应用程序架构而构建的。OTP(开放电信平台)是Erlang的库和中间件的集合。
安装Erlang的方法
1、导入Erlang GPG密钥
运行以下命令以导入Erlang存储库GPG密钥:
sudo apt update
sudo apt install curl software-properties-common apt-transport-https lsb-release
curl -fsSL https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/erlang.gpg
2、将Erlang存储库添加到Ubuntu 22.04
导入密钥后,通过运行以下命令将存储库添加到Ubuntu 22.04系统:
如果是Ubuntu 22.04,则运行以下命令:
sudo apt update
sudo apt install erlang
如果是Ubuntu 20.04/18.04,则运行以下命令:
echo "deb https://packages.erlang-solutions.com/ubuntu $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/erlang.list
3、在Ubuntu上安装Erlang
最后一步是Erlang的实际安装。更新系统软件包列表并安装Erlang,如果是Ubuntu 22.04,则以上已经安装完成,就不用再运行以下命令了:
sudo apt update
sudo apt install erlang
要启动Erlang shell,请运行以下命令:
$ erl
Erlang/OTP 24 [erts-12.1.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]
Eshell V12.1.4 (abort with ^G)
1> ^G
--> q
启动shell后,将打印另一个提示。您可以通过编写一个简单的HelloWorld Erlang代码进行测试:
$ vim hello.erl
% This is a test Hello World Erlang Code
-module(hello).
-import(io,[fwrite/1]).
-export([helloworld/0]).
helloworld() ->
fwrite("Hello, Erlang World!\n").
从Erlang shell编译它。不要忘记每个命令末尾的句号(“句点”):
$ erl
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1]
Eshell V10.1 (abort with ^G)
1> c(hello).
{ok,hello}
然后从Erlang shell运行程序:
2> hello:helloworld().
Hello, Erlang World!
ok
3> ^G
--> q
请参见下面的屏幕截图:
至此,您的Ubuntu 22.04 LTS服务器/桌面上有了一个工作的Erlang。
相关资讯