> Mix does not have a command to install packages outside the context of a > project. Elixir v1.4 will bring some of that functionality but generally > speaking you don't have global packages, they always belong to a project.
The global package installation is definitely a proven useful feature from other language community, like: # this install to user's home directory; then I can play with this module in python shell $ pip install ipython --user # nodejs's npm (Node Package Manager) always install to current directory ./node_modules/..., and doesn't require current directory to be a nodejs project directory, similarly play this package from nodejs REPL # from outside this directory, I can set NODE_PATH=~/node_modules and play with it $ npm install async With Elixir, there are packages like https://hex.pm/packages/benchee are generally useful package, but not specific to any particular project, I want to install it globally, instead of keeping a copy in each of my elixir projects The workaround I found so far is: # Download https://github.com/PragTob/benchee/archive/0.2.0.tar.gz and extract into a temporary directory, cd into it # build an archive ➸ mix archive.build Generated archive "benchee-0.2.0.ez" with MIX_ENV=dev # create my globally installed packages directory ➸ mkdir -vp .mix/libs mkdir: created directory '.mix/libs' # copy the archive or make a link ➸ ln -vnf ~/tmp/benchee-0.2.0/benchee-0.2.0.ez .mix/libs .mix/libs/benchee-0.2.0.ez => ~/tmp/benchee-0.2.0/benchee-0.2.0.ez # start the shell with Erlang's ERL_LIBS env variable to extend system library searching path; here I have freedom to play with this package, no need to maintain a fake elixir project with mix.exs file ... ➸ ERL_LIBS=~/.mix/libs iex Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] Interactive Elixir (1.3.1) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> Benchee.run() ** (UndefinedFunctionError) function Benchee.run/0 is undefined or private. Did you mean one of: * run/1 * run/2 Benchee.run() iex(1)> list = Enum.to_list(1..10_000) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, ...] iex(2)> map_fun = fn(i) -> [i, i * i] end #Function<6.52032458/1 in :erl_eval.expr/5> iex(3)> nil iex(4)> Benchee.run(%{time: 3}, ...(4)> [{"flat_map", fn -> Enum.flat_map(list, map_fun) end}, ...(4)> {"map.flatten", ...(4)> fn -> list |> Enum.map(map_fun) |> List.flatten end}]) Benchmarking flat_map... Benchmarking map.flatten... Name ips average deviation median flat_map 99.64 10036.02μs (±2.24%) 9980.50μs map.flatten 97.07 10302.08μs (±8.86%) 9931.00μs Comparison: flat_map 99.64 map.flatten 97.07 - 1.03x slower :ok This shows it is doable but I hope Elixir can have this feature in mix out of box ... -- You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/CAJctwx61hBt2Ho5Gd2PV7pULr%3D_YU9GETh0BNFFWYKKmLhdz5A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
