So, you followed the installation instructions (either on Unix or Windows) and now you have LuaRocks installed in your machine. Now you probably want to install some rocks (packages containing Lua modules) and use them in your Lua code.
For LuaRocks to function properly, we have a quick checklist to go through first:
Command-line tools (and the system path)
LuaRocks installs some command-line tools which are your interface for managing your rocks: luarocks and luarocks-admin. Make sure the directory where they are located is in your PATH -- the exact location depends on the flags you gave when installing LuaRocks.
Run luarocks to see the available commands:
luarocks
You can get help on any command by using the help command:
luarocks help install
Installing packages is done by typing commands such as:
luarocks install luasocket
The Lua libraries path
To use modules installed with LuaRocks, all you need to do is make sure they are found by Lua's module loading mechanism. The exact location depends on your installation flags, and how to set up the Lua modules path depends on your Lua interpreter and your application: you can use the LUA_PATH and LUA_CPATH environment variables, or update the value of the package.path and package.cpath variables from Lua code.
If you installed the Lua interpreter bundled with LuaRocks on Windows, or if you built both Lua and LuaRocks on Unix with the default paths, the default library path settings will be already appropriate.
Multiple versions using the LuaRocks package loader
If you want to make use of LuaRocks' support for multiple installed versions of modules, you need to load a custom package loader: luarocks.loader.
You should be able to launch the Lua interpreter with the LuaRocks-enabled loader by typing:
lua -lluarocks.loader
Alternatively, you can load the LuaRocks module loader from Lua by issuing this command:
require "luarocks.loader"
If your system is correctly set up so that this command runs with no errors, subsequent calls to require() are LuaRocks-aware and the exact version of each module will be determined based on the dependency tree of previously loaded modules.
Scripts installed by rocks (and the scripts path)
Besides modules, rocks can also install command-line scripts. The default location of this directory (unless you configured your local repository differently) is /usr/local/bin for system-wide installs and ~/.luarocks/bin for per-user installs on Unix and %APPDATA%/luarocks/bin on Windows -- make sure it is in your PATH as well.
Using in Unix systems with sudo
When you use LuaRocks to install a package while you aren't root, the package will get installed in $HOME/.luarocks/ instead of the system-wide (by default, /usr/local/) and become only available for you. Moreover Lua doesn't know with its default setup that packages can be available in the current user's home. If you want to install a package available for all users, you should run it as superuser, typically using sudo.
For example:
sudo luarocks install stdlib
After that, some files may not have correct permissions. For example, if /usr/local/share/lua/5.1/base.lua is only readable by root user, you should at least set them to readable for all users (chmod a+r or chmod 644). For example:
cd /usr/local/share/lua/5.1 sudo chmod a+r *