Install Lua & LuaRocks

Introduction

In this post I’ll show you how to install Lua & LuaRocks on Linux. I’ll be using Ubuntu but this guide applies to Debian too. I’m making this guide for my future self as well in case I have to install it again, It caused me many issues but eventually it worked so yeah, let’s jump into it.

if you have any Lua or LuaRocks installation that is not working I’d suggest to remove everything and start all clean.

You can remove Lua and LuaRocks from the machine completly by using these commands (this will delete anything related to these 2 so be careful, you have been warned, also you should replace the Lua version with the one you have):

sudo apt-get purge --auto-remove lua5.1
sudo apt-get purge --auto-remove luarocks
If prompted you can press ” y ” for yes to confirm deletion. Now that everything’s clean let’s start installing!

Lua & LuaRocks Installation

To get a default installation of Lua and LuaRocks under /usr/local

First, ensure that you have the development tools installed on your system, you can run the command below to install them.

sudo apt install build-essential libreadline-dev unzip

You may need to install curl if you never used curl before for the next section, you can do so by using this command:

sudo apt-get install curl

Then to build and install Lua, run the following commands one by one to download the package in .tar, extract it, build it and install it. You can replace the version number with another one you need for example 5.3.5 or anything else, you can find all the versions directly on www.lua.org . In my case I’ll be installing the Lua 5.1.5.

curl -R -O http://www.lua.org/ftp/lua-5.1.5.tar.gz
tar -zxf lua-5.1.5.tar.gz
cd lua-5.1.5
make linux test
sudo make install
Cool, now Lua is installed. To test it, you can type Lua in the terminal and you should see 2 lines that says something like this:
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
>

You can press Ctrl+C to exit.
You can write ” cd ” to leave the lua installation folder or you can simply close and reopen the terminal again to reset the directory.

Next, we will install LuaRocks. To download and unpack the LuaRocks .tar using following commands.
wget https://luarocks.org/releases/luarocks-3.9.1.tar.gz
tar zxpf luarocks-3.9.1.tar.gz
cd luarocks-3.9.1
./configure --with-lua-include=/usr/local/include

The last command above will attempt to detect your installation of Lua. If you get any error messages, check LuaRocks main docs here:
https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Unix#customizing-your-settings .

If you see an error that says something like ” lua.h can’t be located “, you may be missing the headers, you can install them with this command (replace the version with yours):

sudo apt install liblua5.1-dev

Then finally the last 2 commands:

make
sudo make install

Awesome, Lua & LuaRocks are now installed.

Enjoy!

Website designed by dinolink