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

Installing Erlang OTP

The first thing for setting up an Erlang environment is installing Erlang OTP, a set of Erlang libraries essential for development.

Windows

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.

OS X

If you are an OS X user, to install Erlang OTP, type the following at the Terminal prompt (make sure you have Homebrew installed on your machine):

brew install erlang

Note that if you prefer MacPorts to Homebrew, your command line should be different:

port install erlang +ssl

Linux

The installation process for Linux is similar to OS X, except that 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 Erlang OTP package for any OS.

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, you can read its user guide.

Installing Rebar

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 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 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 Configure | Project Defaults | Project Structure
  • On the main menu, choose File | Other Settings | Default Project Structure

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:

  • 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 have to do is to specify the path to Rebar, so that IntelliJ IDEA can run Rebar commands from the IDE.

You can do it via Configure | Preferences | Other Settings → Erlang External Tools:

path:输入  /usr/local/bin/   即可

Creating a new project

Creating an Erlang project

There are 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 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 ErlangDemo:

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.

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 have to create a run/debug configuration created against the stub Erlang Application. To do this, on the main menu choose Run | Edit Configurations, select the stub Erlang Application, specify the name (here it is hello.hello_world), and specify the application’s module and function:

After that you’ll be able to run your application via the main menu (Run | Run <run configuration name>, the toolbar (), or a even a shortcut (⌃⇧R).

Once you have 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 the stub Erlang Eunit:

IntelliJ IDEA provides a handy Test Runner with support for Eunit. It shows test results, lets you rerun tests of you 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 results 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 Erlang for Great Good tutorial by Fred Hebert.

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 IntelliJ IDEA Quick Start Guide and watch the Video Tutorials.

If you have a question, you can always ask it on StackOverflow (probably it’s already answered).

Providing Feedback

In case you’d like to share your feedback about IntelliJ IDEA or its support for Erlang, feel free to submit an issue in Erlang plugin GitHub repository, or to the IntelliJ IDEA issue tracker.

Refer to the section Reporting Issues and Sharing Your Feedback.

IntelliJ IDEA 比 Sublime 好用多了 哈哈  习惯了vs 和 xcode 还是 IntelliJ IDEA 顺手 !!!!!

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

 
 

Getting Started with Erlang的更多相关文章

  1. [Erlang 0129] Erlang 杂记 VI

    把之前阅读资料的时候记下的东西,整理了一下. Adding special-purpose processor support to the Erlang VM   P23 简单介绍了Erlang C ...

  2. [Erlang 0128] Term sharing in Erlang/OTP 下篇

    继续昨天的话题,昨天提到io:format对数据共享的间接影响,如果是下面两种情况恐怕更容易成为"坑", 呃,恰好我都遇到过; 如果是测试代码是下面这样,得到的结果会是怎样?猜! ...

  3. [Erlang 0127] Term sharing in Erlang/OTP 上篇

    之前,在 [Erlang 0126] 我们读过的Erlang论文 提到过下面这篇论文: On Preserving Term Sharing in the Erlang Virtual Machine ...

  4. [Erlang 0126] 我们读过的Erlang论文

    我在Erlang Resources 豆瓣小站上发起了一个征集活动 [链接] ,"[征集] 我们读过的Erlang论文",希望大家来参加.发起这样一个活动的目的是因为Erlang相 ...

  5. [Erlang 0125] Know a little Erlang opcode

    Erlang源代码编译为beam文件,代码要经过一系列的过程(见下面的简图),Core Erlang之前已经简单介绍过了Core Erlang,代码转换为Core Erlang,就容易拨开一些语法糖的 ...

  6. [Erlang 0124] Erlang Unicode 两三事 - 补遗

    最近看了Erlang User Conference 2013上patrik分享的BRING UNICODE TO ERLANG!视频,这个分享很好的梳理了Erlang Unicode相关的问题,基本 ...

  7. [Erlang 0123] Erlang EPMD

     epmd进程和Erlang节点进程如影随形,在Rabbitmq集群,Ejabberd集群,Couchbase集群产品文档中都会有相当多的内容讲epmd,epmd是什么呢?   epmd 是Erlan ...

  8. [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集

    虽然忙,有些事还是要抽时间做; Erlang Resources 小站 2014年1月~6月资讯合集,方便检索.      小站地址: http://site.douban.com/204209/   ...

  9. [Erlang 0121] 当我们谈论Erlang Maps时,我们谈论什么 Part 3

    Erlang/OTP 17.0 has been released  http://www.erlang.org/download/otp_src_17.0.readme     Erlang/OTP ...

  10. [Erlang 0120] Know a little Core Erlang

      Erlang开发者或多或少都用过或者听说过Core erlang,它是什么样的呢?新建一个测试模块a.erl,如下操作会生成core erlang代码而非a.beam:   Eshell V6.0 ...

随机推荐

  1. linux文件系统底层原理

    Linux文件系统中的文件是数据的集合,文件系统不仅包含着文件中的数据而且还有文件系统的结构,所有Linux 用户和程序看到的文件.目录.软连接及文件保护信息等都存储在其中. 底层原理图: 在讲解各个 ...

  2. vertical-tical

    通常我们需要垂直对齐并排的元素. CSS提供了一些可实现的方法:有时我用浮动float来解决,有时用position: absolute来解决,有时甚至是“肮脏”地手动添加的margin或paddin ...

  3. 【DB2】关闭表的日志功能

    2018.11.19 客户遇到一个问题,在import数据的时候,产生了大量的日志,客户的数据库是HADR模式,通过评估,这几张表是可以允许在备库上不查询的,表中的数据时临时的. 方案一:修改脚本,将 ...

  4. (转)防止人为误操作MySQL数据库技巧一例

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51cto.com/2561410/1321061 防止人 ...

  5. JavaScript中的异步操作

    什么是异步操作? 异步模式并不难理解,比如任务A.B.C,执行A之后执行B,但是B是一个耗时的工作,所以,把B放在任务队列中,去执行C,然后B的一些I/O等返回结果之后,再去执行B,这就是异步操作. ...

  6. OpenGL12-shader(GLSL)着色语言1(代码已上传)

    OpenGL着色语言(GLSL――OpenGL Shading Language)是用来在OpenGL中着色编程的语言, 也即开发人员写的短小的自定义程序,他们是在图形卡的GPU (Graphic P ...

  7. linux下软、硬链接的创建和删除

    linux下软.硬链接的创建和删除 在Linux系统中,内核为每一个新创建的文件分配一个Inode(索引结点),每个文件都有一个惟一的inode号.文件属性保存在索引结点里,在访问文件时,索引结点被复 ...

  8. windows端口查看及进程查找

    1. 使用netstat查看端口 netstat -ano 2. 查找特定端口号: netstat -aon|findstr "port" 3. 查找该端口的进程 tasklist ...

  9. CUBA 7 新特性 (下篇)

    上篇我们主要介绍了 CUBA 7 中前端的一些主要功能.这篇我们介绍一下中间件的一变化和新特性. 中间件功能 前面关于新的界面 API 的描述内容比我预期的要多许多,所以在这一节,我会尽量简单点说! ...

  10. Mysql5.5升级到5.6步骤详解 小版本大版本

    http://blog.csdn.net/i_team/article/details/9935693 小版本升级,先关闭数据库,然后mv直接全部替换掉mysql目录下的bin/ ,lib/ ,sha ...