How to Install Lua Scripting Language in Linux

Lua is a free and open-source, powerful, robust, minimal, and embeddable scripting language. It’s extensible and interpreted scripting language that is dynamically typed, and run by interpreting bytecode with a register-based virtual machine.

Lua runs on all if not most Unix-like operating systems including Linux and Windows; on mobile operating systems (Android, iOS, BREW, Symbian, Windows Phone); on embedded microprocessors (ARM and Rabbit); on IBM mainframes, and many more.

See how Lua programs work in the live demo.

Lua Features:

  • Builds on all systems with a standard C compiler.
  • It’s remarkably lightweight, fast, efficient, and portable.
  • It’s easy to learn and use.
  • It has a simple and well-documented API.
  • It supports several types of programming (such as procedural, object-oriented, functional, and data-driven programming as well as data description).
  • Implements object-oriented via meta-mechanisms.
  • It also brings together straightforward procedural syntax with formidable data description constructs rooted around associative arrays and extensible semantics.
  • Comes with automatic memory management with incremental garbage collection (thus making it perfect for real-world configuration, scripting, and also breakneck prototyping).

How to Install Lua in Linux

Lua package is available in official repositories of major Linux distributions, you can install the latest version using the appropriate package manager on your system.

------- On Debian, Ubuntu & Mint ------- 
$ sudo apt install lua5.3

------- On RHEL, CentOS, Rocky & AlmaLinux ------- 
# yum install epel-release
# yum install lua

------- On Fedora Linux ------- 
# dnf install lua

Note: The current version of the Lua package in the EPEL repository is a little older, therefore to install the latest release, you need to build and install it from the source as explained below.

Install Lua from Sources

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

------- On Debian, Ubuntu & Mint ------- 
$ sudo apt install build-essential libreadline-dev

------- On RHEL, CentOS, Rocky & AlmaLinux and Fedora ------- 
# yum groupinstall "Development Tools" 
# yum install readline readline-devel

Then to build and install the latest release (version 5.4.4 at the time of this writing) of Lua, you need to download the lua source file or run the following commands to download the package tarball, extract, build and install it.

$ mkdir lua_build
$ cd lua_build
$ curl -R -O
$ tar zxf lua-5.4.4.tar.gz
$ cd lua-5.4.4
$ make linux test
$ sudo make install

Once you have installed it, run Lua interpretor as shown.

$ lua 

Lua 5.4.4  Copyright (C) 1994-2022, PUC-Rio

Using your favorite text editor, you can create your first Lua program as follows.

$ vi hello.lua

And add the following code to the file.

print("Hello World")
print("This is and we are testing Lua")

Save and close the file. Then run your program as shown.

$ lua hello.lua
Run Lua Program
Run Lua Program

For more information and to learn how to write Lua programs, go to:

Lua is a versatile programming language being used in numerous industries (from the web to gaming to image processing and beyond), and it’s designed with a high priority for embedded systems.

If you encounter any errors during installation or simply want to know more, use the comment form below to send us your thoughts.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. For those who need a Windows solution, I found a good source that installs Lua 5.1, 5.2, and 5.3, plus LuaRocks for all three. It’s current, and actively maintained. It’s called “Multi-Lua for Windows” and can be found on GitHub:

    You’ll need to install a C compiler, such as MinGW, as this project compiles everything from source, Lua and Luarocks alike.

    Rather than running a Lua interpreter in its own shell window, this Lua runs in the built-in Windows Command Shell window.

  2. Suggestion: After installing Lua, install “LuaRocks“, which is Lua’s package repository (similar to CPAN for Perl and PyPI for Python).

    Lua was designed to be embedded and extensible, so it depends on external libraries for a number of important functions that are internal to most other languages. This includes libraries for working with the host file system, for socket I/O (networking), etc., plus things like unit testing, logging, and so forth.

    Lua’s repo packages are called “rocks” (Lua rocksMoon rocks… get it?), so you can search for, install, update your “rocks” using LuaRocks. LuaRocks installs separate local package caches for each Lua version.

    Lua rocks are typically coded in C, so they need to be compiled from source by LuaRocks in order to be installed. This is usually not an issue for Linux hosts, but for Windows installations you’ll need to have a C compiler installed. I use MinGW for this on my Win platforms.

    Finally, there are two ways to install LuaRocks. I suggest the “bootstrapping” method, which installs LuaRocks as a Lua rock. The advantage of this method is that LuaRocks can be updated in the future by asking LuaRocks to update itself: “luarocks install luarocks“.

  3. This is what worked for me on Linux Mint 19:

    $ mkdir lua_build
    $ cd lua_build
    $ wget
    $ sudo tar -zxf lua-5.3.4.tar.gz
    $ cd lua-5.3.4
    $ sudo make linux test
    $ sudo make install
    • Did you need Lua 5.3.4 for a particular reason? Linuxmint 19 is based on Ubuntu Bionic, which has Lua 5.0, 5.1, 5.2, and 5.3 in its repositories. The repo version for 5.3 is 5.3.3, however. Is there a significant fix for 5.3.4?

  4. I want to know how to do ssh with lua to a remote server and run tcpdump command process in background on remote server.

  5. More Lua features: full lexical closures, co-routines, and multiple return values. There are only 8 data types: nil, Number, String, Boolean, Table, Userdata, Function, and Thread. Any type can be assigned to a variable, and all types are first-class.

    All structured data is made from Tables (associative arrays). Data types and instances of Table/Userdata can have “meta-Tables” that provide powerful extensibility (including object-oriented structure & behavior). Has a very nice C API which helps make it both embeddable and extensible. Nearly a linguistically/semantically perfect language…

  6. I use devilspie2 to embed various things like terminals, browsers, or media players into my desktop, and devilspie uses Lua for configuration. Straight forward and great documentation.


Leave a Reply to Aaron Kili Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.