Question

In NodeJS/NPM, you can create a package.json and run npm install to install all your dependencies in a folder within your project: ./node_modules. (A project can be an app or another module/package.)

Ruby also has a "bundler" system (using a .bundle file) that keeps track of gems specific to a dir (ie project).

Does LuaRocks have similar conventions? Or is it recommeneded to install everything to /usr or $HOME?

So far I've been able to get similiar functionality, but I have to create a custom LuaRocks config file and specify --tree=my_local_lua_rocks_dir every time I want to install a rock. Granted, I can always create a bash script. The point is that it seems I'm going against a convention.

Was it helpful?

Solution

It is possible to install rocks into a directory under the current directory, using the --tree flag:

luarocks install --tree ./lua_modules lpeg

And then you have to configure your package.path and package.cpath variables in Lua (settable via LUA_PATH and LUA_CPATH environment variables) so it finds the modules installed inside it. There are several ways to do this conveniently: this tutorial explains how to do it, with more examples.

OTHER TIPS

Instead of using Vert, I've decided to just edit the LuaRocks config file:

  1. In /etc/luarocks/config.lua :

    rocks_servers = {
     [[http://rocks.moonscript.org/]],
     [[http://luarocks.org/repositories/rocks]]
    }
    
    rocks_trees = {
     [[/usr/local]],
     [[./my_dir]]
    }
    

    ./my_dir is relative to the pwd you're in, not to the location of the config file. Of course, change my_dir to whatever you want.

    "The order of the rock_trees matters: When installing rocks, LuaRocks tries to pick a location to store the rock starting from the bottom of the list; when loading rocks in runtime, LuaRocks scans from the top of the list." From: http://luarocks.org/en/Config_file_format

  2. Then in your .bashrc:

    eval `luarocks path`
    export PATH=$PATH:my_dir/bin
    
  3. However, for certain commands you now have to specify the tree or it will give you a confusing error:

    luarocks make --tree=my_dir
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top