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 http://www.lua.org/ftp/lua-5.4.4.tar.gz $ 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 Lua.org, 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 Tecmint.com and we are testing Lua")
Save and close the file. Then run your program as shown.
$ lua hello.lua
For more information and to learn how to write Lua programs, go to: https://www.lua.org/home.html
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.