Start with an Erlang project
Last modified: 10 August 2022Set up the environment
Before you can proceed with creating a new Erlang project in IntelliJ IDEA, you need a few things installed and configured in your environment.
Install and enable Erlang plugin
In the Settings/Preferences dialog (Ctrl+Alt+S), select the Plugins section on the left.
Switch to the Marketplace tab at the top and search for a plugin called Erlang.
Once the plugin is found, click Install, apply the changes, and close the dialog. Restart the IDE if prompted.
Once the plugin is installed and enabled, the following Erlang-specific settings and configurations become available in IntelliJ IDEA:
note
More information on Run/Debug Configurations in IntelliJ IDEA can be found in the corresponding help section.
Main menu: Run | Edit Configurations

note
More information on Code Style settings in IntelliJ IDEA can be found in the corresponding help section.
Settings / Preferences Ctrl+Alt+S | Editor | Code Style | Erlang

note
More information on Code Inspections in IntelliJ IDEA can be found in the corresponding help section.
Settings / Preferences Ctrl+Alt+S | Editor | Inspections

note
More information on the contents of the Keymap dialog in IntelliJ IDEA can be found in the corresponding help section.
Settings / Preferences Ctrl+Alt+S | Keymap

note
More information on Live Templates in IntelliJ IDEA can be found in the corresponding help section.
Settings / Preferences Ctrl+Alt+S | Editor | Live Templates

note
More information on File and Code Templates in IntelliJ IDEA can be found in the corresponding help section.
Settings / Preferences Ctrl+Alt+S | Editor | File and Code Templates

Settings / Preferences Ctrl+Alt+S | Erlang External Tools

Settings / Preferences Ctrl+Alt+S | Build, Execution, Deployment | Compiler | Erlang Compiler

Install Erlang/OTP framework
Erlang/OTP is a set of Erlang libraries and design principles essential for development.
To install Erlang/OTP, follow the instructions that correspond to your OS:
Download the Erlang/OTP package and run the installation wizard. Take a note of the installation folder path.
Once the installation is over, add the <Erlang installation folder>\bin path to the PATH environment variable:
To verify that Erlang/OTP is installed correctly, type
erl
in the command prompt to make sure the Erlang shell starts up:
Run the following command in the terminal:
brew install erlang
sudo port install erlang +ssl
To verify that Erlang/OTP is installed correctly, start up the Erlang shell from the terminal using the
erl
command:
Run the following command in the terminal:
Ubuntu/Debian:
sudo apt-get update sudo apt-get install erlang
Fedora:
sudo yum install erlang
FreeBSD:
sudo pkg update sudo pkg install erlang
To verify that Erlang/OTP is installed correctly, start up the Erlang shell from the terminal using the
erl
command:
Install and configure Rebar
In addition to Erlang/OTP, you will also need Rebar3: a build tool that helps compile and test Erlang applications. It is the spiritual successor to rebar (v2.x), which is now deprecated.
Rebar3 comes in the form of a portable executable escript file which can be used either as is (script version) or as a means to install a faster, fully compiled form of Rebar3.
The latest stable release of the escript can be downloaded from within IntelliJ IDEA:
In the Settings/Preferences dialog (Ctrl+Alt+S), select Erlang External Tools.
Click Download the latest Rebar 3.
Select the directory where you want the downloaded escript to be saved.
The Path and Version fields will be automatically populated with the corresponding information.
note
Once the path to the Rebar3 executable is specified in the Erlang External Tools dialog, Rebar run/debug configurations become available.
The escript is also available for downloading on the official Rebar3 website.
The process of installing Rebar3 from source, as well as other ways to install and run it are described at length in the tool's official documentation.
note
Windows users should pay attention to extra steps needed to make
rebar3
an executable command in their environment.
Configure the IDE to work with Erlang SDK
The last step of the initial configuration is to let IntelliJ IDEA know where the Erlang SDK is located on your computer.
Once your project is opened, go to the Project Structure dialog Ctrl+Alt+Shift+S.
In the SDKs section, click + to add a new SDK, then select Add Erlang SDK.
In the file chooser dialog that appears, select the directory where you installed Erlang/OTP, for example C:
\Program Files (x86) .\erl23.3 The SDK will be detected and displayed on the list of available SDKs, its lib folder automatically added to the classpath.
If you don’t know where Erlang OTP was installed, check the following directories:
OS
Path
Windows
C:
\Program Files (x86) \erl<version> Linux
/usr /lib /erlang /<version> macOS: MacPorts
/opt /local /lib /erlang /<version> macOS: Homebrew
/usr /local /Cellar /erlang /<version>
Create a new Erlang project
warning
The following is only valid when Erlang plugin is installed and enabled.
You can create a new Erlang project in IntelliJ IDEA in one of two ways:
Use the New Project wizard to create a bare-bones Erlang OTP project with minimal structure.
Generate the project's structure from a Rebar3 template using the Terminal tool window.
Use the New Project wizard
From the main menu, select File | New | Project.
In the dialog that appears, choose Erlang as the project's base.
Ignore the additional frameworks at this point and click Next.
In the dialog that appears, choose Erlang as the project's base.
Ignore additional frameworks at this point and click Next.In this step, Erlang SDK will be pre-selected as the project's SDK - as long as Erlang/OTP framework has been installed and configured. If you have several versions of the SDK installed, choose the one that you need from the list, then click Next.
Give your project a name and choose where to save it. Click Finish to close the dialog.
Generate a new project with Rebar3
Make sure that Rebar3 is installed and added to system PATH.
Open the Terminal tool window Alt+F12.
Enter the following command:
$rebar3 new app myAwesomeProject
This will generate a new project called myAwesomeProject in the current directory from the built-in Rebar3 template called app.

note
Additional configuration may be required for Windows users who want to use the standard command line or PowerShell to run
rebar3
commands.
Once generated, the project needs to be imported into the IDE so that you can work with it. See next section for details.
Import existing Erlang project
If you already have an Erlang project, you can follow the steps from this guide to import it into IntelliJ IDEA.
note
If your project was created using Rebar, make sure to follow this procedure, choosing the project's rebar.config build file as a source.
Erlang project structure
Once your project is imported into IntelliJ IDEA, you can see its structure as a tree in the Project tool window Alt+1. For instance, it will look like this for myAwesomeProject created earlier with Rebar:

In addition to standard files and folders generated by Rebar, IntelliJ IDEA creates a folder called .idea and a file called <yourProjectName>.iml. They contain various settings, such as module structure, VCS mappings, code style settings, and so on, that reflect the configuration of your project from the IDE's perspective.
You will also see your Erlang SDK added to the list of External Libraries. Its contents can be browsed directly from the Project tool window.
Erlang facets
Each Erlang module in your project is supplied with a dedicated Erlang facet. You can use facets to pass parse_transform
compiler directives to modules.
tip
Parse transformations are Erlang modules that export the
parse_transform/2
function. This function is called during compilation, after parsing, and is passed a list of forms, which it modifies and returns as a result.
Apply parse transformations using Erlang facet
Once your project is opened, go to the Project Structure dialog Ctrl+Alt+Shift+S.
In the Facets section, select the Erlang facet that corresponds to the module to which you want to apply parse transforms.
Populate the Parse transforms field that appears on the right with a compiler directive. The format is as follows:
-compile({parse_transform, moduleName}).
tip
More on parse transforms:
Series of blog posts on how to use parse transform capabilities of Erlang to write a macro processor for Erlang, by Philip Robinson.
Erlang parse transforms made easy: the parse_trans application, by Ulf Wiger.
Thanks for your feedback!