How to Install Erlang on Debian 11, 10

This guide will demonstrate how to install Erlang on Debian 11 or 10 Linux using the command-line terminal, leveraging Erlang’s official APT repository for the latest version and future upgrades.

Erlang is a powerful programming language renowned for its ability to build scalable, fault-tolerant systems. Primarily used in telecom, banking, e-commerce, computer telephony, and instant messaging, Erlang’s concurrency, real-time processing, and robust error handling make it a standout choice for high-availability systems.

Key Features of Erlang:

  • Concurrent Processes: Enables handling of numerous simultaneous operations.
  • Fault Tolerance: Designed to detect and recover from failures seamlessly.
  • Distribution: Facilitates the building of distributed systems.
  • Hot Code Swapping: Allows code to be changed without stopping the system.
  • Soft Real-Time: Supports systems with high responsiveness requirements.

Erlang’s architecture is uniquely suited for systems where uptime and reliability are critical. Its ability to handle a massive number of concurrent operations makes it ideal for applications where numerous users are interacting in real-time. Additionally, Erlang’s distributed nature allows for the development of applications that can run on multiple servers seamlessly, further enhancing its reliability and scalability.

As you step into the technical realm of installing Erlang, understanding these benefits and features helps appreciate the robustness and capability Erlang brings to system development and maintenance. The upcoming sections will guide you through the installation process, ensuring you have the latest version of Erlang for your Debian

Debian 12 (Bookworm) is currently not supported, and using Bullseye as the source for Bookworm in production environments is not recommended. While this setup might work temporarily, it can lead to unexpected issues or system instabilities without notice. The article will be updated as soon as an official build for Debian 12 becomes available.

Install Erlang on Debian 11, 10 via APT

Update Debian Before Installing Erlang

To begin, update your Debian system to ensure all packages are current. This step is crucial to prevent potential conflicts during the Erlang installation:

sudo apt update && sudo apt upgrade

Install Initial Required Packages for Erlang Installation

Install Erlang from the official Erlang APT repository for optimal results. Start by installing necessary packages that facilitate the installation process:

sudo apt install dirmngr ca-certificates software-properties-common lsb_release apt-transport-https curl -y

Import Erlang GPG Key and APT Repository

Import the Erlang GPG key to verify package authenticity:

curl -fsSL https://packages.erlang-solutions.com/debian/erlang_solutions.asc | sudo gpg --dearmor -o /usr/share/keyrings/erlang.gpg

Next, add the Erlang APT repository to your system:

echo "deb [signed-by=/usr/share/keyrings/erlang.gpg] https://packages.erlang-solutions.com/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/erlang.list

Keep in mind that there is no official Debian 12 Bookworm build. This command prints your distribution version where $(lsb_release -cs) appears. Only Bullseye or Buster versions are available.

Install Erlang via APT Command on Debian

Update your APT sources to include the newly added Erlang repository:

sudo apt update

Finally, install Erlang with the following command:

sudo apt install erlang
Terminal screenshot showing Erlang installation on Debian Linux
Screenshot of Erlang installation commands in Debian terminal

This sequence of steps ensures a smooth installation of Erlang on Debian 10 or 11, following best practices for system and package management. The inclusion of the Erlang repository ensures access to the latest Erlang versions and future updates.

Launch Erlang Shell on Debian 11, 10

After successfully installing Erlang on Debian, you can initiate the Erlang shell environment with this command:

erl

Essential Erlang Shell Commands

In the Erlang shell, several commands can enhance your interaction and efficiency. Here’s a list of frequently used commands:

  • q(). – Exits the Erlang shell and runtime.
  • c(file). – Compiles the specified Erlang file. Replace file with your file name.
  • b(). – Shows all variable bindings in the current session.
  • f(). – Clears all variable bindings. Useful for resetting the shell environment.
  • f(X). – Removes the binding of the variable X. Replace X with the variable name.
  • h(). – Displays a history of executed commands in the shell.
  • e(N). – Executes the command located at line number N in the command history.
  • v(N). – Retrieves the return value from the command at line number N.
  • catch_exception(boolean). – Configures error handling strictness in the shell. Replace boolean with true or false.
  • rd(Name, Definition). – Defines a new record type Name with the structure specified by Definition.
  • rr(File). – Creates record types based on definitions in the File.
  • rf(). – Clears all record definitions. You can specify certain definitions to clear.
  • rl(). – Lists all current record definitions in the shell.
  • pwd(). – Outputs the present working directory.
  • ls(). – Lists files in the current directory.
  • cd(Directory). – Changes the shell’s working directory to Directory.

These commands provide a fundamental toolkit for navigating and operating within the Erlang shell, contributing to a productive Erlang programming environment.

Create Hello World Test with Erlang on Debian 11, 10

Crafting a Basic Erlang Program

To verify your Erlang installation on Debian, you can create a simple “Hello World” program. This is a standard practice to test a new programming environment.

Step 1: Creating the Erlang File

Start by opening a text editor to write your Erlang code. This guide uses Nano for its simplicity:

nano helloworld.erl

Step 2: Writing the Code

In the Nano editor, input the following Erlang code:

-module(helloworld).  % The name of our module.

-export([helloworld/0]).  % Declaration of the function that we want to export from the module.

helloworld() -> io:format("Hello World!! Thanks Linuxcapable.com ~n").  % What is to happen when the function is called, here: Hello world is to be written on the screen.

Save your work in Nano with CTRL+O, hit ENTER, and then exit using CTRL+X.

Step 3: Opening Erlang Shell

To compile and run your program, open the Erlang shell:

erl

Step 4: Compiling the Program

In the Erlang shell, compile your “Hello World” program:

c(helloworld).

Ensure your current directory in the shell is the same as where helloworld.erl is saved.

Step 5: Running the Program

Execute your compiled Erlang program:

helloworld:helloworld().

This command should display “Hello World” in the shell.

Screenshot of Erlang Hello World program compilation on Debian
Output of Erlang’s Hello World program in Debian terminal

Step 6: Exiting the Erlang Shell

After running the program, exit the Erlang shell with this command:

q().

Managing Erlang on Debian 11, 10

Update and Upgrade Erlang on Debian

Regularly updating and upgrading your system’s packages is a key maintenance task. To check for updates and upgrade all installed packages, including Erlang, use the following commands:

sudo apt update && sudo apt upgrade

This process ensures your Debian system remains current and reduces the risk of security vulnerabilities and software conflicts.

Remove (Uninstall) Erlang From Debian

Step 1: Uninstalling Erlang

If you decide to uninstall Erlang, execute the following command:

sudo apt remove erlang

This command removes the Erlang package from your system.

Step 2: Removing the Erlang APT Repository

For a complete uninstallation, remove the Erlang APT repository from your sources list:

sudo rm /etc/apt/sources.list.d/erlang.list

Removing the repository prevents future updates of Erlang from being fetched.

Step 3: Optional – Removing the GPG Key

To fully clean up, you may also want to remove the GPG key:

sudo rm /usr/share/keyrings/erlang.gpg

This step is optional but recommended for users who want to ensure no remnants of Erlang remain on their system.

Conclusion

That’s a wrap! We’ve journeyed through installing Erlang on Debian, set up the essential environment, and even dabbled in creating a classic “Hello World” program. Just remember to keep your system updated regularly for smooth sailing. Whether you’re exploring Erlang out of curiosity or for professional projects, it’s a robust language with tons to offer.

For further information, visit the Erlang documentation.

Leave a Comment


Your Mastodon Instance
Share to...