📜  ubuntu erlang 23 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:20:44.233000             🧑  作者: Mango

ubuntu erlang 23 - Shell-Bash

When it comes to building a robust and efficient scalable system, using the right technologies can make all the difference. Erlang is one such technology that has gained a lot of popularity in recent years. With its ability to handle concurrency well, it makes it a perfect choice for building real-time applications, message-passing systems, and distributed systems. And when it comes to running Erlang on Ubuntu, the combination is unbeatable.

Installing Erlang 23 on Ubuntu

To install Erlang 23 on Ubuntu, you can follow these simple steps:

  1. Add the Erlang Solutions repository to Ubuntu:
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && sudo dpkg -i erlang-solutions_2.0_all.deb
  1. Update the package information:
sudo apt-get update
  1. Install Erlang 23:
sudo apt-get install erlang

You can also install specific packages of Erlang 23, such as Erlang runtime, Erlang documentation, or Erlang debugger, by running:

sudo apt-get install erlang-base
sudo apt-get install erlang-doc
sudo apt-get install erlang-dbg
Using Erlang Shell - Bash

One of the best things about Erlang is its shell, which is quite powerful and offers several features that make it a must-have for any Erlang programmer. To use Erlang's shell, you can simply type the following command in your terminal:

erl

Once you start the Erlang shell, you will notice that it has a unique prompt that starts with '>' and ends with '.'. This prompt shows that Erlang is waiting for you to enter a command. To exit the shell, you can simply type 'q().' or use 'Ctrl+Z' or 'Ctrl+C' to terminate it.

Here are some of the features that you can use in the Erlang shell:

Running simple commands

You can execute simple commands in the Erlang shell, such as performing arithmetical operations, printing text, or defining variables. For example, to calculate 2 + 2, you can type:

1> 2 + 2.
4
Debugging with the shell

The Erlang shell also provides several functions that enable you to debug your code, such as tracing, breakpoints, and error checking. For example, to trace a function call, you can type:

1> dbg:tracer().
{ok,<0.71.0>}
2> dbg:p(all, c).
{ok,[{matched,nonode@nohost,1}]}
3> lists:reverse([1,2,3]).
(<0.75.0>) call lists:reverse([1,2,3])
(<0.75.0>) return [3,2,1]
[3,2,1]
Using the help system

Erlang also includes an extensive help system that provides a wealth of information about Erlang functions, modules, and commands. To access the help system, you can use the 'help()' and 'doc()' commands. For example, to get help on the 'io:format' function, you can type:

1> help(io:format).
io:format(Fmt, Data) -> ok
io:format(Device, Fmt, Data) -> ok

Types:
Fmt = string()
Data = [term...]
Device = [stream() | {file_name(), Mode}]
ok

Format output according to a format string. The format string is a string that consists of ordinary characters (not %), which are copied to the output, and format specifications, each of which causes fetching of the next element in Data, converting it according to the format specification, and outputting it.

Returns the atom ok if successful.

ok

Using the Erlang shell with Ubuntu is a powerful combination that every programmer should consider. With its unique features, powerful functions, and extensive help system, the Erlang shell is an essential tool for anyone looking to develop scalable, robust real-time applications.