Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In elixir, How do i install packages globally?

Can I use mix to install some packages globally? I'd like a behaviour like npm's global option or gem's install - it could be useful for packages I use everywhere like csv or yaml.

like image 804
Yingce Avatar asked Nov 05 '15 15:11

Yingce


3 Answers

There is no such thing in Elixir, you always use dependencies in the context of a project. Solutions like archives or escripts are meant to solve specific problems, they do not allow package sharing between projects.

However, there is no need to worry about sharing frequently used packages. Hex, the package manager, already cache those and it will take care of handling it for you.

like image 122
José Valim Avatar answered Nov 08 '22 13:11

José Valim


Certain packages will provide an archive file that you can install globally.

http://elixir-lang.org/docs/v1.1/mix/Mix.Tasks.Archive.Install.html

For example Phoenix:

mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v1.0.3/phoenix_new-1.0.3.ez

This allows access to the mix phoenix.new task globally. There is not anything specific for allowing the installation of libraries that are available in all your mix projects though.

like image 30
Gazler Avatar answered Nov 08 '22 13:11

Gazler


For Elixir scripts, you can virtually install global packages by using erun. By compiling erun with your dependencies, you can run

$ erun foo.exs

(erun is just an escript.)

https://github.com/s417-lama/erun

like image 1
s417-lama Avatar answered Nov 08 '22 13:11

s417-lama