Getting Started with Erlang
Erlang is a great language that lets you build highly concurrent applications. This tutorial will teach you how to quickly get started with it.
In this section:
- Preliminary steps
- Setting up IntelliJ IDEA
- Creating a new project
- Running and debugging an application
- Running Eunit tests
- Running Rebar commands
Installing Erlang OTP
The first thing for setting up an Erlang environment is installing Erlang OTP, a set of Erlang libraries essential for development.
If you are a Windows user, download the
Erlang OTP package
and run the installation wizard. Once the installation is over, add the installation path plus
\bin to the PATH environment variable.
If you are an macOS user, to install Erlang OTP, type the following at the Terminal prompt (make sure you have Homebrew installed on your machine):
brew install erlang
If you prefer MacPorts to Homebrew, your command line should be different:
port install erlang +ssl
The installation process for Linux is similar to macOS, except that instead of
port you have to use
apt-get (a Linux package management utility):
apt-get install erlang
Verifying Erlang OTP installation
To verify that Erlang OTP is installed correctly, run the Erlang shell by typing
erl in a Terminal prompt:
To learn more about the Erlang shell, read its user guide.
In addition to Erlang OTP, you’ll also need Rebar, a build tool that helps compile and test Erlang applications. The easiest way to install it on your machine is to download its sources and build it locally:
git clone git://github.com/rebar/rebar.git $ cd rebar $ ./bootstrap Recompile: src/getopt ... Recompile: src/rebar_utils ==> rebar (compile)
Congratulations! You now have a self-contained script called "rebar" in your current working directory. Place this script anywhere in your path and you can use rebar to build OTP-compliant apps.
Setting up IntelliJ IDEA
Now when Erlang OTP and Rebar are set up, it’s time to download and install IntelliJ IDEA. Keep in mind, that for Erlang development you can use IntelliJ IDEA Community Edition (which is free and open-source).
Once the IDE is up and you see its Welcome screen, go to , then click Browse repositories, locate the Erlang plugin and install it:
After installing the plugin, restart IntelliJ IDEA.
Configuring an Erlang SDK
One more thing you’ll have to do to configure IntelliJ IDEA is to add an Erlang SDK.
To do that, change the structure of the default project. Open the default project structure in one of the two ways:
- On the Welcome screen, go to
- On the main menu, choose
Then, add an Erlang SDK by specifying the path to the Erlang OTP installation directory.
If you don’t know where Erlang OTP was installed, check the following directories:
- MacPorts, macOS:
- Homebrew, macOS:
The final adjustment you have to do is to specify the path to Rebar, so that IntelliJ IDEA can run Rebar commands from the IDE.
Creating a new project
Creating an Erlang project
Then choose Erlang in the left pane, and click Next.
IntelliJ IDEA prompts you to choose an Erlang SDK (which you've already configured):
After that you’ll be asked to specify the name of your project and its directory. The following image shows the resulting Erlang project with the name
Creating a Rebar project
Instead of a pure Erlang project, you might want to create a Rebar project. To do that, type the following code at the Terminal prompt:
rebar create-app appid=<project name>
Once the project has been created, import it into IntelliJ IDEA to make it possible to open this project in the IDE.
Importing a project into IntelliJ IDEA
You can import a project into IntelliJ IDEA in several ways. Let's explore importing from the Welcome screen.
To import an existing project into IntelliJ IDEA, click Import on the Welcome Screen, and choose the project directory. IntelliJ IDEA offers you to either import the project from existing sources, or from an external model (a build file).
If your project uses Rebar, select the corresponding option when asked.
Running and debugging an application
To run an application, you have to create a run/debug configuration created against the stub Erlang Application.
To do this, on the main menu choose , select the stub Erlang Application, specify the name
(here it is
hello.hello_world), and specify the application’s module and function:
Running Eunit tests
Running Rebar commands
Learning IntelliJ IDEA
IntelliJ IDEA is a Java IDE in the first place, however it’s also a platform and IDE for other languages, such as Erlang, Python, Ruby, PHP, and many other. To learn more about IntelliJ IDEA, it’s worth checking out the section Discover IntelliJ IDEA and watch the Video Tutorials.
If you have a question, you can always ask it on StackOverflow (probably it’s already answered).
Refer to the section Reporting Issues and Sharing Your Feedback.