Introduction: Erlang Package Manager

Neha Singh
The Complete Guide to Erlang
3 min readFeb 18, 2019

Hex is a package manager for Erlang. Hex was written by Eric Meadows-Jönsson and first released December on 23, 2013.
Hex helps us to work faster, make debugging process easier, tries to remove all possible issues and help us become a good developer.
Any Hex package follows the below basic file structure.
├── LICENSE.md
├── README.md
├── config
│ └── config.exs
├── deps
│ ├── earmark
│ └── ex_doc
├── doc
│ ├── 404.html
│ ├── Chameleon.html
│ ├── api-reference.html
│ ├── dist
│ ├── fonts
│ ├── index.html
│ └── search.html
├── lib
│ ├── chameleon
│ └── chameleon.ex
├── mix.exs
├── mix.lock
└── test
├── chameleon_test.exs
└── test_helper.exs

It has mix.exs file that is a very important component and contains some of the required metadata for the package.
(Mix is a build tool that provides tasks for creating, compiling, and testing Erlang projects, managing its dependencies, and more.
The foundation of Mix is a project. A project can be defined by using Mix.Project in a module, usually placed in a file named mix.exs.)

defmodule PackageName.MixProject do
use Mix.Project
def project() do
[
app: :packagename,
version: “0.1.0”,

description: description(),
package: package(),
deps: deps(),
name: “PackageName”,
source_url: “https://github.com/username/packagename
]
end

defp deps() do
[
{:ex_doc, “~> 0.14”, only: :dev},
{:foobar, git: “https://github.com/elixir-lang/foobar.git", tag: “0.1”}
{:foobar, path: “path/to/foobar”}
]
end
defp description() do
“A few sentences (a paragraph) describing the project.”
end
defp package() do
[
name: “packagename”,
files: [“lib”, “mix.exs”, “README*”, “LICENSE*”],
maintainers: [“XYZ”],
licenses: [“GPL 3.0”],
links: %{“GitHub” => “https://github.com/org/packagename”}
organization: “my-org”
]
end
end

The mix.exe file has some important section to consider like

version — Hex need packages to follow semantic versioning. Major versions make breaking differences, minor versions add features and patches are created for bug fixing.

description-Writing a meaningful description is important. This helps users to identify the correct package when they are looking for required packages, or what they happen to read on hex.pm when they are browsing.

deps- This isn’t hex-specific, but the dependencies can be loaded to hex, directly from git, or from a local path. This implies one can create and use a hex package that was never actually published.

package[:name]-This is the name given to the package on hex.pm and in the search.

package[:organization]-It is optional, but is useful if we want to publish a package to a private repository.

Some Useful Commands that a Hex User should Know:

1.mix hex.info: This command given with no arguments returns information about local hex installation. Hex also checks if there is any update available on running this command.

2.mix hex.info <package>: This command gives information about all the releases of a particular package and gives its most current description.

3.mix hex.info <package> <version> : This gives information about the released versions of a particular package.

4.mix hex .search: This command searches for the packages matching the search string in the hex.pm.

5.mix hex.docs: This helps us to find documentation on the packages.

6.mix hex .user: This command helps to register for an account in Hex.pm without this one cannot publish a package.

7.mix hex.config: This command reads, updates and delete local hex configuration.

8.mix hex .audit: It shows all the dependencies that has expired.

9.mix hex.publish: This command helps to publish a package with the community. Only requirement that one should have is that the mix.exs file has the necessary metadata and he/she should be a registered user.

--

--