CentOSRHEL Based

How To Install Erlang on CentOS Stream 10

Install Erlang on CentOS Stream 10

In this tutorial, we will show you how to install Erlang on CentOS Stream 10. Erlang, a concurrent and functional programming language, is renowned for building scalable and fault-tolerant systems. Its applications range from telecommunications to financial services. It is highly valued for its capacity to handle numerous concurrent processes, making it a perfect choice for real-time systems and distributed applications. Are you looking to leverage Erlang’s power on a stable and modern Linux distribution? CentOS Stream 10 offers a robust platform. It provides a rolling-release environment, making it ideal for developers who want to stay up-to-date with the latest technologies. In this comprehensive guide, we will walk you through the process of installing Erlang on CentOS Stream 10. We will provide step-by-step instructions, troubleshooting tips, and best practices to ensure a smooth and successful installation.

This article is designed for developers, system administrators, and technology enthusiasts. It caters to those eager to harness Erlang’s capabilities on CentOS Stream 10. Whether you are setting up a development environment or deploying a production system, this guide will provide you with the knowledge and confidence to get Erlang running efficiently. So, let’s dive in and get started!

Prerequisites

Before you begin the Erlang installation process, there are several prerequisites that you need to address. Ensuring that your system meets these requirements will help prevent potential issues and streamline the installation.

System Requirements

To install Erlang on CentOS Stream 10, your system should meet the following minimum hardware specifications:

  • Processor: A modern multi-core processor.
  • Memory: At least 2 GB of RAM. However, 4 GB or more is recommended for development environments.
  • Storage: 20 GB of free disk space to accommodate the operating system, Erlang, and any dependencies.

These specifications are a baseline. Actual requirements might vary based on the scale and complexity of your Erlang projects. For resource-intensive applications, consider allocating more memory and processing power.

Root or Sudo Access

You need either root access or sudo privileges to install Erlang. This is because the installation process involves modifying system files and installing software packages, which require elevated permissions. To verify that you have sudo access, open a terminal and run:

sudo whoami

If the output is “root,” you have the necessary privileges. If not, you will need to gain sudo access through your system administrator.

Internet Connectivity

A stable internet connection is essential for downloading the required packages and dependencies. Erlang and its related components are typically distributed through online repositories. Maintaining a reliable connection ensures that you can fetch the necessary files without interruption.

Required Dependencies

Erlang relies on several dependencies to function correctly. These include essential build tools, development libraries, and other utilities. Installing these dependencies before Erlang can prevent installation failures and ensure compatibility.

  • Essential Build Tools and Packages: These tools are necessary for compiling Erlang from source. They include:
    • GCC (GNU Compiler Collection): A compiler system. Crucial for compiling C and C++ code.
    • Make: An automation tool. Manages the build process.
    • Autoconf: A tool for producing shell scripts to automatically configure software source code packages.
    • Automake: A tool used for automatically generating ‘Makefile.in’ files compliant with the GNU Coding Standards.
  • Development Libraries: Erlang requires certain libraries for various functionalities:
    • OpenSSL-devel: Provides cryptographic functions. Crucial for secure communication.
    • ncurses-devel: Enables text-based user interfaces.
    • zlib-devel: Offers data compression capabilities.
  • GUI Dependencies for Graphical Tools: If you plan to use Erlang with graphical interfaces, you might need:
    • GTK (GIMP Toolkit): Used for creating graphical user interfaces.
    • wxWidgets: A cross-platform GUI library.

To install these dependencies on CentOS Stream 10, use the following command:

sudo dnf install gcc make autoconf automake openssl-devel ncurses-devel zlib-devel gtk3-devel wxGTK3-devel

Installation Methods

There are two primary methods for installing Erlang on CentOS Stream 10. You can use the package manager or compile from source code. Each method has its advantages and disadvantages, depending on your specific needs and preferences.

Method 1: Package Manager Installation

Installing Erlang using the package manager is the simplest and most straightforward method. CentOS Stream 10 uses DNF (Dandified Yum) as its package manager. This method typically installs a pre-built binary package, which is easier and faster than compiling from source.

Repository Configuration

Before installing Erlang, you may need to configure the Erlang Solutions repository. This repository provides up-to-date Erlang packages. Add the Erlang Solutions repository by creating a new repository file:

sudo nano /etc/yum.repos.d/erlang.repo

Add the following content to the file:

[erlang-solutions]
 name=Erlang Solutions Repository
 baseurl=https://packages.erlang-solutions.com/rpm/centos/$releasever/$basearch
 gpgcheck=1
 gpgkey=https://packages.erlang-solutions.com/rpm/erlang-solutions.asc
 enabled=1

Save the file and exit. This configuration tells DNF where to find the Erlang packages.

Package Installation Steps

With the repository configured, you can now install Erlang using DNF:

sudo dnf install erlang

This command downloads and installs the Erlang package and any required dependencies from the Erlang Solutions repository. DNF handles the dependency resolution automatically, ensuring that all necessary components are installed.

Verification Process

After the installation is complete, verify that Erlang is correctly installed by checking the Erlang version:

erl -version

The output should display the Erlang version number. This confirms that Erlang is installed and accessible from your terminal.

Method 2: Source Code Installation

Installing Erlang from source code provides more flexibility and control over the installation process. It allows you to customize the build options and install Erlang in a specific directory. This method is suitable for advanced users who need specific configurations or want to use the latest development version.

Downloading Source Code

First, download the Erlang source code from the official Erlang website or GitHub. Use the following command to download the source code using wget:

wget https://erlang.org/download/otp_src_27.2.3.tar.gz

Replace “otp_src_27.2.3.tar.gz” with the actual file name of the Erlang source code.

Configuration Options

Before building Erlang, you can configure the build options using the ./configure script. This script checks your system for dependencies and configures the build environment. To configure Erlang, navigate to the extracted source directory and run:

./configure --prefix=/opt/erlang

The --prefix option specifies the installation directory. Change “/opt/erlang” to your desired installation path.

Build Process

After configuring the build, compile the Erlang source code using the make command:

make

This process may take some time, depending on your system’s hardware. Once the compilation is complete, install Erlang using the following command:

sudo make install

This installs Erlang in the directory specified by the --prefix option during configuration.

Step-by-Step Installation Guide

This section provides a detailed, step-by-step guide for installing Erlang on CentOS Stream 10. It covers both the package manager and source code installation methods, offering clear instructions for each.

System Preparation

Before starting the installation, ensure your system is up-to-date and has the necessary build dependencies.

System Update Commands

Update your system by running:

sudo dnf update

This command updates all installed packages to their latest versions, ensuring that you have the most recent security patches and bug fixes.

Installing Build Dependencies

Install the essential build dependencies using:

sudo dnf install gcc make autoconf automake openssl-devel ncurses-devel zlib-devel

These packages are necessary for compiling Erlang from source code. If you are using the package manager method, these dependencies might be automatically installed, but it is still a good practice to ensure they are present.

Setting Up Environment Variables

Setting up environment variables simplifies the process of accessing Erlang from any location in the terminal. Add the following lines to your .bashrc or .zshrc file:

export ERLANG_HOME=/opt/erlang
 export PATH=$ERLANG_HOME/bin:$PATH

Replace “/opt/erlang” with your Erlang installation directory. Apply the changes by running:

source ~/.bashrc

Or, if you are using Zsh:

source ~/.zshrc

Building from Source

If you choose to install Erlang from source, follow these steps:

Downloading and Extracting Source Code

Download the Erlang source code:

wget https://erlang.org/download/otp_src_27.2.3.tar.gz

Extract the downloaded file:

tar -zxf otp_src_27.2.3.tar.gz

Navigate to the extracted directory:

cd otp_src_27.2.3

Running Configuration Scripts

Run the configuration script:

./configure --prefix=/opt/erlang

This configures the build environment and specifies the installation directory.

Compilation Process

Start the compilation process:

make

This step compiles the Erlang source code. It may take a while, depending on your system’s resources.

Installation Commands

Install Erlang:

sudo make install

This installs Erlang in the specified directory.

Post-Installation Setup

After installing Erlang, configure the environment and test the installation.

Environment Configuration

Ensure that the environment variables are correctly set in your .bashrc or .zshrc file:

export ERLANG_HOME=/opt/erlang
 export PATH=$ERLANG_HOME/bin:$PATH

Apply the changes:

source ~/.bashrc

Or, if you are using Zsh:

source ~/.zshrc

Path Settings

Verify that the Erlang executable is in your system’s PATH. Run:

echo $PATH

The output should include the Erlang installation directory (e.g., /opt/erlang/bin).

Testing the Installation

Test the Erlang installation by starting the Erlang shell:

erl

If Erlang starts successfully, you should see the Erlang shell prompt:

Erlang/OTP 27 [erts-14.2.3] [source] [64-bit] [smp:8:8] [ds:8:8:16] [async-threads:1]
 

 Eshell V27.2.3  (abort with ^G)
 1>

Type halt(). to exit the Erlang shell.

Configuration and Optimization

After installing Erlang, you can configure and optimize it to suit your specific needs. This section covers basic configuration settings and performance tuning tips.

Basic Configuration

Basic configuration involves setting environment variables, system paths, and user permissions to ensure Erlang runs smoothly and securely.

Environment Variables

Erlang uses several environment variables to control its behavior. The most important ones are:

  • ERLANG_HOME: Specifies the Erlang installation directory.
  • PATH: Includes the Erlang executable directory, allowing you to run Erlang commands from any location.

Set these variables in your .bashrc or .zshrc file:

export ERLANG_HOME=/opt/erlang
 export PATH=$ERLANG_HOME/bin:$PATH

Apply the changes by running:

source ~/.bashrc

Or, if you are using Zsh:

source ~/.zshrc

System Paths

Ensure that the Erlang executable directory is included in the system’s PATH. You can check this by running:

echo $PATH

If the Erlang directory is not included, add it to your .bashrc or .zshrc file.

User Permissions

Ensure that the user running Erlang has the necessary permissions to access the Erlang installation directory and any related files. You can change the ownership of the Erlang installation directory using the chown command:

sudo chown -R youruser:yourgroup /opt/erlang

Replace “youruser” and “yourgroup” with your actual username and group.

Performance Tuning

Erlang’s performance can be tuned by adjusting memory settings, CPU optimization, and network configuration. Optimizing these settings can improve the efficiency and scalability of your Erlang applications.

Memory Settings

Erlang’s memory usage can be controlled using command-line flags. The most important flags are:

  • +K: Sets the maximum number of processes that can be run concurrently.
  • +P: Sets the maximum number of ports that can be opened.
  • +MBas: Sets the amount of memory allocated to atoms.

You can set these flags when starting the Erlang shell:

erl +K 100000 +P 1000000 +MBas 1024

These settings increase the maximum number of processes and ports and allocate more memory to atoms, which can improve performance for applications that use a large number of concurrent processes or atoms.

CPU Optimization

Erlang can take advantage of multi-core processors by using SMP (Symmetric Multi-Processing). To enable SMP, use the +smp flag:

erl +smp

You can also specify the number of schedulers to use with the +swt flag:

erl +smp +swt 8

This starts Erlang with SMP enabled and uses 8 schedulers, which can improve performance on systems with 8 or more cores.

Network Configuration

Erlang’s network performance can be tuned by adjusting the TCP settings. The most important settings are:

  • TCP_NODELAY: Disables Nagle’s algorithm, which can reduce latency for small packets.
  • SO_REUSEADDR: Allows multiple processes to bind to the same address and port.

You can set these options using the gen_tcp module:

{ok, Socket} = gen_tcp:listen(Port, [binary, {packet, 0}, {nodelay, true}, {reuseaddr, true}]).

This code creates a TCP listener socket with TCP_NODELAY and SO_REUSEADDR enabled.

Verification and Testing

After installing and configuring Erlang, it is important to verify that it is working correctly. This section covers the steps to verify the installation and test basic functionality.

Command-Line Verification

The simplest way to verify that Erlang is installed correctly is to check the Erlang version from the command line:

erl -version

This command should display the Erlang version number, confirming that Erlang is installed and accessible from your terminal.

Version Checking

You can also check the Erlang version from within the Erlang shell:

erl

When the Erlang shell starts, it displays the Erlang version number in the header:

Erlang/OTP 27 [erts-14.2.3] [source] [64-bit] [smp:8:8] [ds:8:8:16] [async-threads:1]
 
Eshell V27.2.3  (abort with ^G)
1>

Basic Functionality Testing

Test basic Erlang functionality by running a simple Erlang program. Create a file named hello.erl with the following content:

-module(hello).
 -export([start/0]).
 

 start() ->
  io:format("Hello, Erlang!~n").

Compile the program:

erlc hello.erl

Run the program:

erl -noshell -s hello start -s init stop

This command compiles and runs the hello.erl program, which prints “Hello, Erlang!” to the console.

Running Test Cases

For more comprehensive testing, you can use the EUnit testing framework. Create a test file named hello_tests.erl with the following content:

-module(hello_tests).
 -include_lib("eunit/include/eunit.hrl").
 

 hello_test() ->
  ?assertEqual("Hello, Erlang!\n", hello:start()).

Compile the test file:

erlc hello_tests.erl

Run the tests:

erl -noshell -pa . -s eunit_listener text -s hello_tests test -s init stop

This command compiles and runs the hello_tests.erl test file, which verifies that the hello:start() function returns the expected output.

Troubleshooting

Even with careful preparation, you may encounter issues during the Erlang installation process. This section provides solutions and workarounds for common installation errors.

Common Installation Errors

Some common installation errors include missing dependencies, build failures, and configuration issues.

Dependencies Issues

Missing dependencies are a common cause of installation errors. Ensure that all required dependencies are installed before attempting to install Erlang. Use the following command to install the dependencies:

sudo dnf install gcc make autoconf automake openssl-devel ncurses-devel zlib-devel

If you encounter errors related to missing libraries, search for the corresponding development packages and install them using DNF.

Build Failures

Build failures can occur due to various reasons, such as compiler errors or incorrect configuration options. Check the error messages carefully and try to identify the cause of the failure. Some common solutions include:

  • Cleaning the build directory: Run make clean to remove any previous build files and start the build process from scratch.
  • Adjusting configuration options: Review the configuration options and ensure that they are appropriate for your system.
  • Updating build tools: Ensure that your build tools (GCC, Make, Autoconf, Automake) are up-to-date.

Congratulations! You have successfully installed Erlang. Thanks for using this tutorial for installing the Erlang programming language on your CentOS Stream 10 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