Site icon DesignLinux

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:

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
Run Lua Program

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.

Exit mobile version