使用apt在Ubuntu 20.04上安裝Erlang

導入 Erlang GPG Key

1
2
3
sudo apt update
sudo apt install software-properties-common apt-transport-https
wget -O- https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo apt-key add -

把Erlang Repository 加入 Ubuntu 20.04的 apt sources list

1
echo "deb https://packages.erlang-solutions.com/ubuntu focal contrib" | sudo tee /etc/apt/sources.list.d/erlang.list

使用 apt 安裝 Erlang

1
2
sudo apt update
sudo apt install erlang

檢查

1
2
3
4
5
6
7
knightli@epyc:~$ erl
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:64:64] [ds:64:64:10] [async-threads:1] [jit]

Eshell V12.2.1  (abort with ^G)
1> 
User switch command
 --> q

編輯 hello.erl測試文件

1
2
3
4
5
6
7
% This is a test Hello World Erlang Code
-module(hello).
-import(io,[fwrite/1]).
-export([helloworld/0]).

helloworld() ->
   fwrite("Hello, Erlang World!\n").

編譯並運行

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
knightli@epyc:~$ erl
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:64:64] [ds:64:64:10] [async-threads:1] [jit]

Eshell V12.2.1  (abort with ^G)
1> c(hello).
{ok,hello}
2> hello:helloworld().
Hello, Erlang World!
ok
3>  
User switch command
 --> q
记录并分享
Built with Hugo
Theme Stack designed by Jimmy