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.
- 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 http://www.lua.org/ftp/lua-5.3.4.tar.gz $ 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.
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 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.