Getting Started with Erlang

Source: Internet
Author: User

Getting Started with Erlang

Erlang is a great language this lets you build highly concurrent applications. This tutorial'll teach you what to quickly get started with it.

In the section:

  • Preliminary steps
    • Installing Erlang OTP
      • Windows
      • OS X
      • Linux
    • Verifying Erlang OTP Installation
    • Installing Rebar
  • Setting up IntelliJ idea
    • Configuring an Erlang SDK
    • Configuring Rebar
  • Creating a new project
    • Creating an Erlang project
    • Creating a Rebar Project
    • Importing a project into the IntelliJ idea
  • Running and debugging an application
  • Running Eunit Tests
  • Running Rebar Commands
  • Additional
    • Learning Erlang
    • Learning IntelliJ Idea
    • Providing Feedback

Preliminary steps

Installing Erlang OTP

The first thing for setting up an Erlang environment was installing Erlang OTP, a set of Erlang libraries essential for Dev Elopment.

Windows

If You is a Windows user, download the Erlang OTP package and run the Installation wizard. Once the installation is over, add the installation path plus to the \bin PATH environment variable.

OS X

If you are a OS X user, to install Erlang OTP, type the following in the Terminal prompt (make sure you have Homebrew ins Talled on your machine):

brew install erlang

Note that if you prefer macports to Homebrew, and your command line should is different:

port install erlang +ssl

Linux

The installation process for Linux are similar to OS X, except this instead of "brew" or "port" you have to use "Apt-get" ( A Linux Package management utility):

apt-get install erlang

Note that you can always download the latest version of the Erlang OTP package for any OS.

Verifying Erlang OTP Installation

To verify this Erlang OTP is installed correctly, run the Erlang shell by typing in erl a Terminal prompt:

To learn more on the Erlang shell, you can read the IT User Guide.

Installing Rebar

In the addition to Erlang OTP, you'll also need Rebar, a build tool that helps compile and test Erlang applications. The easiest-to-install it on your. 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 are now having a self-contained script called "rebar" in your current working directory. Place the script anywhere in your path and you can use the rebar to build otp-compliant apps.

Setting up IntelliJ idea

Now when Erlang OTP and Rebar is set up, it's time to download and install the IntelliJ idea. Keep in mind, this for Erlang development you can use IntelliJ idea Community Edition (which are free and open-source).

Once the IDE is up and we see its Welcome screens, go to Configure | Plugins, 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 the to do to configure IntelliJ the idea are to add an Erlang SDK.

To does, change the structure of the default project. Open The default project structure in one of the ways:

    • On the Welcome screens, go to Configure | Project Defaults | Project Structure
    • On the main menu, choose File | Other Settings | Default Project Structure

Then, add a Erlang SDK by specifying the path to the Erlang OTP installation directory.

If you don ' t know where Erlang OTP is installed, check the following directories:

    • Windows: C:\Program Files\erl<version>
    • Linux: /usr/lib/erlang/<version>
    • MacPorts, OS X: /opt/local/lib/erlang/<version>
    • Homebrew, OS X: /usr/local/Cellar/erlang/<version>

Configuring Rebar

The final adjustment you has to do are to specify the path to Rebar, so that IntelliJ idea can run Rebar commands from the Ide.

Can do it via Configure | Preferences | Other Settings→erlang External Tools:

Path: Enter/usr/local/bin/

Creating a new project

Creating an Erlang project

There is several ways to create a new Erlang project. The easiest one is to use the New Project Wizard from the Welcome screen.

Click Create New Project:

Then choose Erlang in the left pane, and click Next.

IntelliJ idea Prompts-Choose an Erlang SDK (which you ' ve already configured):

After this 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 ErlangDemo :

Creating a Rebar Project

Instead of a pure Erlang project, you might want to create a Rebar project. To does, 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 the IntelliJ idea

You can import a project to IntelliJ idea in several ways. Let's explore importing from the Welcome screen.

To import a existing project into IntelliJ idea, click Import in the Welcome screen, and choose the project directory . IntelliJ Idea offers-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.

When importing a Rebar project, make sure to enable the option Fetch dependencies with Rebar:

Running and debugging an application

To run an application, you had to create a run/debug configuration created against the stub Erlang application. To does this, on the main menu choose Run | Edit configurations, select the stub Erlang application, specify the name (here it hello.hello_world is), and specify the Applicat Ion ' s module and function:

After so you're able to run your application via the main menu (run | Run <run configuration Name>, the toolbar (), or a even a shortcut (?? R ).

Once You has a run/debug configuration, you can also debug your application via the main menu (run | Debug ' <run configuration name>, the toolbar (), or a shortcut ( ?D ):

For more information, refer to the concept of a run/debug configuration and the procedural sections Running and debugging.

Running Eunit Tests

Running eunit tests is similar to Running an application, but needs a different run/debug configuration, created against T He stub Erlang eunit:

IntelliJ idea provides a, handy Test Runner with the support for Eunit. It shows test results, lets you rerun tests of your choice, jump to failed tests, etc.:

Running Rebar Commands

Running Rebar Commands is also possible right from the Ide–with the help of the Erlang Rebar run/debug Configuration :

Note that if your Rebar commands run tests, you can use a Erlang Rebar eunit run/debug configuration to see test Resul TS in a Test Runner.

Additional

Learning Erlang

To learn Erlang, we recommend you-to-start by reading the official Erlang User Guide, and of course the learn you Some ERL Ang for great Good Tutorial by Fred Hebert.

Learning IntelliJ Idea

IntelliJ idea was 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 on IntelliJ idea, it's worth checking out of the IntelliJ idea Quick Start guide and watch the Video Tutoria Ls.

If you had a question, you can always ask it on stackoverflow (probably it ' s already answered).

Providing Feedback

In the case of you ' D-share your feedback about IntelliJ idea or its-support for Erlang, feel-to-submit an issue in E Rlang plugin GitHub Repository, or to the IntelliJ idea issue tracker.

Refer to the sections Reporting issues and sharing Your Feedback.

IntelliJ idea is more useful than Sublime, haha used to vs and Xcode or IntelliJ idea handy!!!!!

Https://www.jetbrains.com/idea/help/getting-started-with-erlang.html

Getting Started with Erlang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.