IntelliJ IDEA 2023.2 Help

Start with an Erlang project

Set 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

  1. Press Control+Alt+S to open the IDE settings and then select Plugins.

  2. Switch to the Marketplace tab at the top and search for a plugin called Erlang.

  3. Once the plugin is found, click Install, apply the changes, and close the dialog. Restart the IDE if prompted.

    Installing the Erlang plugin

Once the plugin is installed and enabled, the following Erlang-specific settings and configurations become available in IntelliJ IDEA:

Main menu: Run | Edit Configurations

Settings for Erlang External Tools

Settings Control+Alt+S | Editor | Code Style | Erlang

Erlang Code Style Settings

Settings Control+Alt+S | Editor | Inspections

Erlang Inspection Settings

Settings Control+Alt+S | Keymap

Erlang Shortcuts

Settings Control+Alt+S | Editor | Live Templates

Erlang Live Template Settings

Settings Control+Alt+S | Editor | File and Code Templates

Erlang File and Code Template Settings

Settings Control+Alt+S | Erlang External Tools

Settings for Erlang External Tools

Settings Control+Alt+S | Build, Execution, Deployment | Compiler | Erlang Compiler

Erlang Compiler Settings

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:

  1. Download the Erlang/OTP package and run the installation wizard. Take a note of the installation folder path.

  2. Once the installation is over, add the <Erlang installation folder>\bin path to the PATH environment variable:

    Adding Erlang to PATH

  3. To verify that Erlang/OTP is installed correctly, type erl in the command prompt to make sure the Erlang shell starts up:

    Verifying the Erlang OTP is installed correctly
  1. Run the following command in the terminal:

    Homebrew:

    brew install erlang

    MacPorts:

    sudo port install erlang +ssl
  2. To verify that Erlang/OTP is installed correctly, start up the Erlang shell from the terminal using the erl command:

    Verifying the Erlang OTP is installed correctly
  1. 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
  2. To verify that Erlang/OTP is installed correctly, start up the Erlang shell from the terminal using the erl command:

    Verifying the Erlang OTP is installed correctly

    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 (the 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:

    1. Press Control+Alt+S to open the IDE settings and then select Erlang External Tools.

    2. Click Download the latest Rebar 3.

    3. Select the directory where you want the downloaded escript to be saved.

      Locating Rebar executable

      The Path and Version fields will be automatically populated with the corresponding information.

    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.

    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.

    1. Once your project is opened, go to the Project Structure dialog Control+Alt+Shift+S.

    2. In the SDKs section, click + to add a new SDK, then select Add Erlang SDK.

    3. 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.

      Configuring the Erlang SDK

    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

    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

    1. Go to 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.

    2. In the dialog that appears, choose Erlang as the project's base.

      Ignore additional frameworks at this point and click Next.

      Running rebar3 from IDE terminal
    3. 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.

      Running rebar3 from IDE terminal
    4. Give your project a name and choose where to save it. Click Finish to close the dialog.

      Running rebar3 from IDE terminal

    Generate a new project with Rebar3

    1. Make sure that Rebar3 is installed and added to system PATH.

    2. Open the Terminal tool window Alt+F12.

    3. 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.

    Running rebar3 from IDE terminal

    Once generated, the project needs to be imported into the IDE so that you can work with it. For more information, refer to the next section.

    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.

    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:

    Erlang Rebar3 New Project Structure

    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.

    Apply parse transformations using Erlang facet

    1. Once your project is opened, go to the Project Structure dialog Control+Alt+Shift+S.

    2. In the Facets section, select the Erlang facet that corresponds to the module to which you want to apply parse transforms.

    3. Populate the Parse transforms field that appears on the right with a compiler directive. The format is as follows:

      -compile({parse_transform, moduleName}).

      Erlang Facets
    Last modified: 07 September 2023