How to Install Lua Scripting Language in Linux

Lua is a free and open source, powerful, robust, minimal and embeddable scripting language. It’s an extensible and interpreted scripting languages that is dynamically typed, 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 works 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.

$ sudo apt install lua5.3	                #Debian/Ubuntu systems 
# yum install epel-release && yum install lua	#RHEL/CentOS systems 
# dnf install lua		                #Fedora 22+

Note: The current version of Lua package in EPEL repository is 5.1.4; therefore to install the current release, you need to build and install it from 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.

$ sudo apt install build-essential libreadline-dev      #Debian/Ubuntu systems 
# yum groupinstall "Development Tools" readline		#RHEL/CentOS systems 
# dnf groupinstall "Development Tools" readline		#Fedora 22+

Then to build and install the latest release (version 5.3.4 at the time of this writing) of Lua, run the following commands to download the package tar ball, extract, build and install it.

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

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

$ lua 
Lua Interpretor
Lua Interpretor

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 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.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

12 thoughts on “How to Install Lua Scripting Language in Linux”

  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.


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.