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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

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

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

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.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

12 Responses

  1. Brainstorms says:

    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. Brainstorms says:

    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. Benji says:

    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
    • Ravi Saive says:


      Thanks for sharing the instructions, hope it will help Mint users..

    • Brainstorms says:

      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. Leema Singh says:

    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. Brainstorms says:

    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. Jeff says:

    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.

Your email address will not be published. Required fields are marked *

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