Vinicius Brasil

August 26, 2021

Installing libraries inside IEx

You want to test that new Ecto.Changeset function, or that payment processing library without having to install it in your project. You open up Interactive Elixir (IEx) in your terminal, but as there is no mix.exs file to list your dependencies, you can't use external libraries.

image.png

Good thing is that Elixir has a built-in build tool called Mix that can be used inside IEx. The Mix.install/2 function is available since Elixir 1.12.0.

iex> Mix.install([:decimal, {:jason, "~> 1.0"}, :ecto])
:ok

iex> Jason.encode(%{hello: "world"})
{:ok, "{\"hello\":\"world\"}"}

About Vinicius Brasil

Building cool stuff with Elixir, OTP and Ruby. Majoring in Theology and musician.