OpenResty® Scalable Web Platform by Extending NGINX with Lua

OpenResty XRay

Advanced observability built for OpenResty and more


limited time offer

Request TRIAL today and receive a diagnostic REPORT
Learn more

Using LuaRocks

Arnaud Brousseau , 16 Nov 2016 (created 07 Aug 2011)

WARNING! This page is deprecated. Use of LuaRocks with OpenResty is strongly discouraged since OpenResty provides its own package manager, OPM.

This sample demonstrates usage of LuaRocks with OpenResty. It's been tested on Linux and Mac OS X, with the standard Lua interpreter or with LuaJIT.

LuaRocks is a deployment and management system for Lua modules. LuaRocks allows one to install Lua modules as self-contained packages called "rocks", which also contain version dependency information.

We assume that you have installed OpenResty into the default location, i.e., /usr/local/openresty. You can adjust the paths in this sample according to the actual installation prefix of your OpenResty installation. If you haven't installed OpenResty yet, check out the Download and Installation pages.

Install LuaRocks

First of all, let's install LuaRocks:

Download the LuaRocks tarball from As of this writing, the latest version is 2.3.0, but we'll use 2.0.13 for compatibility throughout this sample.

tar -xzvf luarocks-2.0.13.tar.gz
cd luarocks-2.0.13/
./configure --prefix=/usr/local/openresty/luajit \
    --with-lua=/usr/local/openresty/luajit/ \
    --lua-suffix=jit \
sudo make install

Install the Lua MD5 library with LuaRocks

In this sample, we'll use the Lua MD5 library to serve as an example, so let's install it with LuaRocks:

sudo /usr/local/openresty/luajit/luarocks install md5

Known issues

Pior to OpenResty, it's known that turning lua_code_cache on will cause LuaRocks atop Lua Nginx Module to throw out the following exception in error.log:

lua handler aborted: runtime error: stack overflow

If you're using any version of OpenResty before, please consider upgrading.