How to install LuaRocks on Linux

Endrit Qerreti

Endrit Qerreti

LuaRocks is the package manager for lua packages, which allows you to manage lua packages on your machine.

LuaRocks is cross platform, and it supports Linux, Windows and MacOS.

Installing LuaRocks on Linux can be done by installing it from the source, and from the main repositories of Ubuntu.

In this tutorial, we'll be installing LuaRocks on Ubuntu, by downloading its source code and then building it manually on our machine.

Install LuaRocks on Linux

Step 1 - Download LuaRocks

LuaRocks tarball can be easily downloaded from your terminal, by using a tool like curl.

To download LuaRocks source code, simply run the command below.

curl -o lua.tar.gz

Note: The command above will download LuaRocks source code into a file called lua.tar.gz.

Step 2 - Install LuaRocks

Method 1: Install luarocks from Ubuntu repositories

To install luarocks without having to build it from the source, you can do so by downloading the official package of luarocks luarocks which is available on the main repository on Ubuntu 22.04.

sudo apt install luarocks

Method 2: Install luarocks from the source

In order to be able to install LuaRocks, you must have Lua programming language installed on your machine. Lua is needed as you won't be able to install LuaRocks without it.

You can check out our tutorial how to install lua.

Next, you need to extract the content of LuaRocks tarball file that you downloaded. To do so, simply run the command below.

tar -zxvf lua.tar.gz

Once extracted, proceed to nagivate to the directory of LuaRocks. This is the directory that got created after extraction.

cd luarocks-3.9.2

Next, proceed to make the source ready so that you can install it

./configure && make && sudo make install

Once the source is configured, you should be able to run the command below and install LuaRocks.

sudo luarocks install luasocket

Step 3 - Verify LuaRocks Installation

To verify that LuaRocks was installed correctly, and that you can use it, run LuaRocks by checking the version that you installed on your machine.

luarocks --version


In this tutorial, you learned how to install LuaRocks package manager on Linux.

In this tutorial, we used Ubuntu 22.04, and installed LuaRocks by building its official tarball source.