UbuntuUbuntu Based

How To Install Erlang on Ubuntu 24.04 LTS

Install Erlang on Ubuntu 24.04

Erlang, a functional programming language designed for building scalable and fault-tolerant systems, has become increasingly popular in the world of modern software development. Whether you’re developing distributed systems, real-time applications, or telecommunications software, Erlang provides a robust platform for creating efficient and reliable solutions. In this comprehensive guide, we’ll walk you through the process of installing Erlang on Ubuntu 24.04, exploring various methods and best practices to ensure a smooth setup for your development environment.

What is Erlang?

Erlang is a functional programming language and runtime system developed by Ericsson in the late 1980s. Initially created for telecommunications applications, Erlang has since found widespread use in various domains due to its unique features and capabilities.

Key features of Erlang include:

  • Concurrency-oriented programming
  • Fault tolerance and high availability
  • Distributed computing support
  • Hot code swapping
  • Soft real-time capabilities

These features make Erlang an excellent choice for building scalable, distributed systems, messaging platforms, and applications that require high concurrency and fault tolerance. Some well-known projects and companies using Erlang include WhatsApp, Discord, and RabbitMQ.

Prerequisites

Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • A system running Ubuntu 24.04 LTS
  • Basic knowledge of command-line operations
  • Sudo privileges on your Ubuntu system
  • A stable internet connection for downloading packages

With these prerequisites met, you’re ready to begin the Erlang installation process on your Ubuntu 24.04 system.

Preparing Your System

Before installing Erlang, it’s crucial to ensure that your Ubuntu system is up-to-date and has all the necessary dependencies. Follow these steps to prepare your system:

1. Update Package Lists

Open a terminal and run the following command to update your package lists:

sudo apt update

2. Upgrade Existing Packages

After updating the package lists, upgrade your existing packages to their latest versions:

sudo apt upgrade -y

3. Install Necessary Dependencies

Erlang requires several dependencies to compile and run properly. Install them using the following command:

sudo apt install -y build-essential autoconf libncurses5-dev openssl libssl-dev fop xsltproc unixodbc-dev

With your system prepared, you’re now ready to install Erlang using one of the methods described below.

Installing Erlang from Official Repositories

The simplest way to install Erlang on Ubuntu 24.04 is by using the official Erlang Solutions repository. This method ensures that you get the latest stable version of Erlang. Follow these steps:

1. Add Erlang Solutions Repository

First, download and add the Erlang Solutions repository signing key:

wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
sudo apt-key add erlang_solutions.asc

Next, add the repository to your system:

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

2. Update Package Lists

Update your package lists to include the new repository:

sudo apt update

3. Install Erlang Packages

Now, you can install Erlang using the following command:

sudo apt install -y esl-erlang

4. Verify the Installation

To verify that Erlang has been installed correctly, open the Erlang shell by typing:

erl

You should see the Erlang prompt. Type halt(). to exit the Erlang shell.

Installing Erlang from Source

For those who need more control over the installation process or require a specific version of Erlang, installing from source is an excellent option. Here’s how to do it:

1. Download the Source Code

Visit the official Erlang download page and copy the link to the latest source tarball. Then, use wget to download it:

wget https://github.com/erlang/otp/archive/OTP-24.0.tar.gz

Note: Replace the URL with the latest version available at the time of installation.

2. Extract the Source Files

Extract the downloaded tarball:

tar -xzvf OTP-24.0.tar.gz
cd otp-OTP-24.0

3. Configure the Build

Run the configure script to prepare the build:

./configure

4. Compile and Install Erlang

Compile and install Erlang with these commands:

make
sudo make install

5. Set Up Environment Variables

Add Erlang to your PATH by editing your ~/.bashrc file:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Installing Erlang using asdf Version Manager

For developers who work with multiple versions of Erlang or other programming languages, using a version manager like asdf is highly recommended. Here’s how to install Erlang using asdf:

1. Install asdf

First, install asdf by following these steps:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
source ~/.bashrc

2. Add Erlang Plugin

Add the Erlang plugin to asdf:

asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git

3. Install Specific Erlang Version

Install the desired version of Erlang:

asdf install erlang 24.0

4. Set Global Erlang Version

Set the installed version as the global Erlang version:

asdf global erlang 24.0

Post-Installation Steps

After successfully installing Erlang, there are a few additional steps you should take to configure your development environment:

1. Configuring Erlang

Create a configuration file for Erlang:

touch ~/.erlang

You can add custom Erlang configurations to this file as needed.

2. Setting Up Project Directories

Create a directory for your Erlang projects:

mkdir ~/erlang_projects
cd ~/erlang_projects

3. Creating a Simple Erlang Program

To test your Erlang installation, create a simple “Hello, World!” program:

echo '-module(hello).
-export([world/0]).

world() ->
    io:format("Hello, World!~n").' > hello.erl

erlc hello.erl
erl -noshell -s hello world -s init stop

If everything is set up correctly, you should see “Hello, World!” printed to the console.

Troubleshooting Common Issues

While installing Erlang on Ubuntu 24.04, you may encounter some common issues. Here are solutions to a few of them:

Dependency Conflicts

If you encounter dependency conflicts, try the following:

  • Remove conflicting packages: sudo apt remove [package-name]
  • Clean apt cache: sudo apt clean
  • Update and upgrade again: sudo apt update && sudo apt upgrade

Compilation Errors

If you face compilation errors when installing from source:

  • Ensure all dependencies are installed
  • Check for any error messages and install missing libraries
  • Try using a different version of Erlang

Path and Environment Variable Problems

If Erlang is installed but not recognized:

  • Verify the installation path: which erl
  • Ensure the path is correctly added to your ~/.bashrc file
  • Reload your shell configuration: source ~/.bashrc

Best Practices for Erlang Development on Ubuntu

To make the most of your Erlang development environment on Ubuntu 24.04, consider the following best practices:

1. Use Version Control

Always use a version control system like Git for your Erlang projects. Initialize a Git repository in your project directory:

git init

2. Set Up a Proper Development Environment

Use an Integrated Development Environment (IDE) or a text editor with Erlang support. Some popular options include:

  • Visual Studio Code with the Erlang extension
  • IntelliJ IDEA with the Erlang plugin
  • Emacs with erlang-mode

3. Keep Erlang Updated

Regularly check for Erlang updates and upgrade when necessary:

sudo apt update
sudo apt upgrade esl-erlang

If using asdf, update Erlang with:

asdf update erlang
asdf install erlang latest
asdf global erlang latest

Congratulations! You have successfully installed Erlang. Thanks for using this tutorial for installing the Erlang programming language on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Erlang website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button