Install Erlang on Centos 7 with Efficient Steps – OrcaCore

Posted on

Install Erlang on Centos 7 with Efficient Steps - OrcaCore

Install Erlang on Centos 7 with Efficient Steps – OrcaCore

This guide provides a comprehensive walkthrough on how to Install Erlang on Centos 7. The Erlang programming language stands out as a general-purpose, concurrent, and garbage-collected programming language. It also functions as a robust runtime system. The sequential aspect of Erlang is a functional language characterized by eager evaluation, single assignment, and dynamic typing, which concurrently adheres to the Actor model.

Follow the detailed steps provided below by the Orcacore team to successfully Install Erlang Programming Language on your Centos 7 system.

Before diving into the Erlang Programming Language setup, ensure you are logged into your server as a non-root user with sudo privileges. If needed, refer to our guide on Initial Server Setup with Centos 7.

1. Erlang Programming Language Setup on Centos 7

Centos repositories do not natively include Erlang packages. Therefore, manual addition to your server is required. Begin by updating your local package index using the following command:

sudo yum update -y

Next, install the EPEL (Extra Packages for Enterprise Linux) repository using:

sudo yum install epel-release -y

Add Erlang Repository

Now, navigate to the Erlang Downloads page to acquire the latest RPM package. You can achieve this using the wget command:

# sudo wget https://packages.erlang-solutions.com/erlang-solutions-2.0-1.noarch.rpm
# sudo rpm -Uvh erlang-solutions-2.0-1.noarch.rpm

Install Erlang

With the Erlang repository added, you can now install the Erlang package on your Centos 7 system with the following command:

sudo yum install erlang -y

Alternatively, for a complete Erlang installation encompassing the Erlang/OTP platform and all its associated applications, use:

sudo yum install esl-erlang -y

2. Test Erlang Installation on Centos 7

This section guides you through testing your Erlang installation by creating a simple "Hello World" project.

First, create a hello.erl file using your preferred text editor (e.g., vi):

sudo vi hello.erl

Add the following content to the file:

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

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

Save and close the file after adding the content.

Next, compile the program from within the Erlang shell.

To access the Erlang shell on Centos 7, execute:

erl
Install Erlang on Centos 7

Then, execute the following commands within the Erlang shell:

1> c(hello).
{ok,hello}
2> hello:helloworld().
Hello from OrcaCore, Erlang World!
ok

To exit the Erlang shell, use:

3> q().

For further information, consult the Erlang Documentation page.

Conclusion

Erlang is instrumental in constructing high-performance web servers and APIs, capable of managing a substantial number of concurrent connections with minimal downtime. You have now learned to Install Erlang on Centos 7 and create a basic project.

Hope you enjoyed this guide. You may also find these articles helpful:

  • How To Install OpenSSL 3 on Centos 7
  • How To Install OpenJDK 17 on Centos 7
  • Chkrootkit Antivirus For Centos 7
  • Memcached Setup on Centos 7
  • Installing FFmpeg on Centos 7
  • Manage Users on Centos 7

FAQs

What is Erlang, and why install it on CentOS 7?

Erlang is a programming language and system used to build reliable and scalable software. Installing Erlang on CentOS 7 lets you create and run programs that handle many tasks at the same time, like phone systems, messaging apps, and databases.

How do I verify that Erlang is installed correctly?

After the Erlang installation, you can verify it by accessing the Erlang shell with the erl command.

How do I uninstall Erlang from CentOS 7?

You can easily remove it with the following command:
sudo yum remove erlang

Alternative Solutions for Installing Erlang on CentOS 7

While the above method using the Erlang Solutions repository is a common and effective approach, here are two alternative methods to Install Erlang on Centos 7.

1. Using a Package Manager (if available through other repositories)

While CentOS 7 doesn’t have Erlang in its base repositories, some third-party repositories might contain Erlang packages. This method is less common but worth exploring.

Explanation:

This approach relies on the availability of Erlang packages in a non-standard repository that you might already have configured or can add. It simplifies the installation process if a suitable repository exists. However, be cautious about the source and maintainership of such repositories to avoid security risks or outdated packages.

Steps:

  1. Check Existing Repositories: Use yum repolist to list all enabled repositories. Look for any that might contain Erlang packages.

  2. Search for Erlang Packages: If you suspect a repository has Erlang, use yum search erlang to confirm.

  3. Install Erlang (if found): If Erlang packages are found, install them using sudo yum install erlang.

Caveats:

  • This method is highly dependent on the availability of Erlang packages in third-party repositories.
  • Package versions in these repositories might not be the latest.
  • Security and maintenance of the repository are your responsibility.

2. Building from Source

A more involved but also more flexible method is to build Erlang from source code. This gives you full control over the build process and allows you to install a specific version of Erlang. This method is useful if you need a very specific version of Erlang not available in pre-built packages, or if you want to customize the build process.

Explanation:

Building from source gives you the most control over the installation, allowing you to configure specific build options and ensure compatibility with your system. It requires more technical expertise but offers the greatest flexibility.

Steps:

  1. Install Build Dependencies: You’ll need a C compiler (like GCC), make, and other development tools.

    sudo yum groupinstall "Development Tools"
    sudo yum install ncurses-devel openssl-devel unixODBC-devel java-devel
  2. Download the Erlang/OTP Source Code: Visit the Erlang website or GitHub repository to download the source code for your desired version. Use wget or curl to download the .tar.gz file. For example:

    wget https://erlang.org/download/otp_26.2.tar.gz
  3. Extract the Source Code:

    tar -xzf otp_26.2.tar.gz
    cd otp_26.2
  4. Configure the Build:

    ./configure --prefix=/usr/local/erlang

    The --prefix option specifies the installation directory. Adjust this as needed.

  5. Build Erlang:

    make
  6. Install Erlang:

    sudo make install
  7. Set Environment Variables: Add the Erlang binaries to your PATH environment variable. Edit your ~/.bashrc or ~/.bash_profile file and add the following line:

    export PATH=$PATH:/usr/local/erlang/bin

    Then, source the file:

    source ~/.bashrc
  8. Verify Installation: Run erl to start the Erlang shell and verify the installation.

Code Example (Hello World – same as before, for completeness):

% hello.erl
-module(hello).
-export([helloworld/0]).

helloworld() ->
  io:format("Hello, world!n").

Compile and run:

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

Caveats:

  • This method requires more technical knowledge and can be time-consuming.
  • You are responsible for managing dependencies and ensuring the build process completes successfully.
  • Upgrading Erlang in the future will also require rebuilding from source.

In summary, the Erlang Solutions repository provides a straightforward way to Install Erlang on Centos 7, while using other repositories or building from source offers alternative approaches with different trade-offs in terms of ease of use and control. Choose the method that best suits your needs and technical expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *