Installing dependencies in Elixir
Asked Answered
R

1

37

Is there a way to install a dependency for an Elixir project directly through the command line using mix or mix hex?

I am aware of the option for searching the hex registry via

$ mix hex.search httpoison

Package    Version  URL
httpoison  0.11.0   https://hex.pm/packages/httpoison

However, I am looking for something like

$ mix hex.install httpoison

which will modify my mix.exs file, adding the name and most recent version of the dependency to the deps function and the application name to the applications list and then run

$ mix deps.get

to pull and compile the dependency.

Reparable answered 12/8, 2015 at 3:36 Comment(0)
E
37

If you are looking for something similar to npm install --save, then this does not exist in Elixir. You install things by adding them to deps: in the mix.exs file in your project then running mix deps.get.

The other way you may wish to install certain applications is via a mix archive allowing this mix task to be run globally. One example of this is phoenix.new for creating new phoenix applications which can be installed by running:

mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v0.16.1/phoenix_new-0.16.1.ez
Evanston answered 12/8, 2015 at 6:36 Comment(1)
does this mean I can't have some global environment that I can write small one-off scripts against? For example, as a long time rubyist I have many single-file utility scripts that don't use bundler but often have dependencies that assume a standard set of global gems.Gillis

© 2022 - 2024 — McMap. All rights reserved.