How to Install and Setup Lua in Linux
Last Updated :
06 Nov, 2022
Lua is a programming language that is used for scripting, embedded applications, as well as for quite other technologies including plugins and text editors. Lua is a lightweight and open-source programming language it has been used in game development engines like Love 2D cocos2D, text editors like Neovim, desktop applications like MySQL workbench, WireShark, etc. It is quite easy to learn and start with Lua, so in this article, we will install Lua on a Linux machine.
Features of Lua
Lua is a simple extensible and portable programming language, it can be used for creating simple as well as dynamic applications with minimal memory footprint. We will look into the major features of Lua as a programming language.
Cross-platform
Lua is cross-platform because its interpreter of compiled bytecode is written in ANSI C. So, Lua has a relatively simple C API that can be embedded into applications. So this feature of Lua allows to run it virtually anywhere making it truly a cross-platform language.
Lightweight
Lua has an extremely simple and thorough source code, making it lightweight and efficient in both performance and robustness. This feature of Lua makes it viable for easily integrating into multiple platforms and has a wide range of applications ranging from embedded applications to game engines.
Dynamic Data types
Since lua is a dynamically typed language like python, javascript, ruby, etc the variable doesn’t have types so to speak but the literal values stored inside of that variable. This makes it extremely easy for rapid prototyping of applications and creating high-level applications without explicit control over memory and the types.
Efficiency
Lua is considered to be one of the fastest languages among dynamically typed programming languages. The reasons are the mentioned points the light-weightiness of runtime and writing speed. The speed can be even further increased by using the Just In Time compiler for Lua and making efficient use of memory and space. Not only it is faster in terms of runtime speed but it is quite easier to write code in Lua.
Installation
There are just a couple of steps you need to follow in order to install Lua in your system. If you are on Ubuntu or any Debian-based distribution, you can install with the apt package as a single command.
Debian based distributions( e.g. Ubuntu)
sudo apt install lua5.4
Arch Based Distributions
sudo pacman -S lua
Fedora
dnf install lua
With brew package manager
brew install lua
You can check for other specific details or build from the source from the documentation given on the official website of Lua.
Verify Installation
Now, once the Lua runtime is installed, we can verify the same with the Lua command, if the command opens a REPL it means that the installation was successful.
lua
You can now press CTRL + C to exit out of the repl. Lua ships with its own repl which allows us to write a bunch of Lua code for testing out a few things quickly. Though it can’t save those states, it can be used for quick prototyping of Lua scripts.
You can also check if Lua is properly installed by checking with the version command,
lua -v
This command will give you the installed version of Lua in your system. This also gives an indication the installation of Lua was successful.
Install from Source
We can even build Lua from source using some baked-in binaries and source code which is open source. We can follow the below procedure for installing Lua from the source, the method is roughly similar in various operating systems but the configuration is definitely OS specific.
Install from the source code:
We need to install the source code zip files from the website with the link, here you can choose the version you require and install it as your preference either manual installation and unzipping or installing with wget or curl and unzipping with tar.
wget http://www.lua.org/ftp/lua-5.4.4.tar.gz
OR
curl -R -O http://www.lua.org/ftp/lua-5.4.4.tar.gz
This will create a zip file in your current directory with the name lua-5.4.4.tar.gz or any other version you have installed.
Unzip the folder:
tar xvfz lua-5.4.4.tar.gz
This will unzip the file and store the source code in a folder called the lua-5.4.4 or any version you might have downloaded, this folder will contain the necessary files for building the Lua runtime.
After the folder has been created, we can change our location and move it into that unzipped folder. There we need to run the make command and set certain parameters for the installation of the Lua runtime.
cd lua-5.4.4
make linux install INSTALL_TOP=/usr/local/lua/5_4_4 MYLIBS=”-lncurses”
This should build the environment for Lua, and it will be available locally for the folder to run Lua.
If this didn’t work for you, you can try an alternate installation command with make as it will minimally install the Lua runtime without specifying the installation path and the library to use.
cd lua-5.4.4
make linux test
sudo make install
This will give you access to the Lua runtime and thereby you have installed Lua in your system.
If it isn’t working for you to run Lua from anywhere on your system, there are a few environment variables you can set. Still, there are a few configurations needed for the environment to access the Lua binaries to be able to detect it globally on your system.
Set symbolic links for identifying the binary or header files for Lua runtime. What these below commands will do is set a symbolic link to the binary files for Lua from the current zipped and built binaries in the local directory to the system Lua binaries. This will ensure the Lua binaries are working properly
ln -s /usr/local/lua/5_4_4/bin/lua /usr/local/bin/
ln -s /usr/local/lua/5_4_4/bin/luac /usr/local/bin/
ln -s /usr/local/lua/5_4_4/include/lauxlib.h /usr/local/include/
ln -s /usr/local/lua/5_4_4/include/lua /usr/local/include/
ln -s /usr/local/lua/5_4_4/include/luaconf.h /usr/local/include/
ln -s /usr/local/lua/5_4_4/include/lua.h /usr/local/include/
ln -s /usr/local/lua/5_4_4/include/lua.hpp /usr/local/include/
ln -s /usr/local/lua/5_4_4/include/lualib.h /usr/local/include/
ln -s /usr/local/lua/5_4_4/lib/liblua.a /usr/local/lib/
Also, you need to add environment variables for the Lua binaries into the bashrc or bash_profile for the proper working of the Lua ecosystem. So, add these lines to your ~/.bash_profile.
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
This will append the lib paths and package configuration of the system and update the environment variables.
Using the Lua REPL
We can quickly get a view of Lua by using the repl and writing the basic program to understand the syntax of the Lua programming language.
We can use the print function to print text to the console.
print("Hello, Geeks!")
This function takes in a string “”, and returns the text to the console, we can also perform quick mathematical and logical operations inside the REPL.
So, this is how we can use REPL to use simple and general operations. For further reading, you can view the Lua documentation.
Running Lua scripts
We can use the Lua source file to interpret and run the scripts. So the Lua command can take in a few parameters and one of which is a source file to run.
lua <file_name>.lua
So, passing the name of the script will run the code and display the output if any.
So, this was the installation and a basic overview of the Lua programming language.
Similar Reads
How to Install SQLmap in Linux?
SQL Injection Vulnerability can be detected and exploited through various automated tools. It is an open-source cyber security tool that introduces its most powerful SQLi detection engine. All the task of flaw detection and gaining access to the database is done in an automated way. This tool is so
3 min read
How to Install GNU Octave in Linux?
Octave is open-source, free available for many of the platforms. It is actually a High-level Language. It comes up with a text interface along with an experimental graphical interface. It is also used for various Machine Learning algorithms for solving various numeric problems. You can say that it i
2 min read
How to Install Scala in Linux?
Prerequisite: Introduction to Scala Before, we start with the process of Installing Scala on our System. We must have first-hand knowledge of What the Scala Language is and what it actually does? Scala is a general-purpose, high-level, multi-paradigm programming language. It is a pure object-oriente
3 min read
How to install burp suit in linux system
Burp Suite is a vulnerability scanner. It is a collection of tools that perform vulnerability scanning in various applications. It is used for web penetration testing and mobile penetration testing. Burp Suite Pro uses professionals primarily hackers. Burp Suite is available in two versions first on
2 min read
How to Install opencv in C++ on Linux?
OpenCV stands for open-source Computer Vision Library. It is a library that provides infrastructure for computer vision and machine learning applications. It has more than 2500 Computer vision and machine learning algorithms. They can be used to track objects, recognize faces and objects, stitch ima
3 min read
How to Install LISP on Linux?
LISP (List programming) is the second-oldest high-level programming language after Fortran. It has a fully parenthesized prefix notation. Installing LISP on Linux:Follow the below steps to install LISP on Linux: Step 1: Install SBCL compiler. Steel Bank Common Lisp (SBCL) is the most common Lisp com
1 min read
How to Install OpenJDK in Linux
If you have started Java learning, you must have the Java Development Kit (JDK) installed on your system. OpenJDK is a free and open-source version of Java that provides everything you need to develop and run Java applications. Itâs a popular choice for developers because itâs easy to install and wo
4 min read
How to Install MySQL/MariaDB in Linux?
Installing MySQL or MariaDB in Linux is a straightforward process that provides you with powerful relational database management systems (RDBMS). MySQL and MariaDB are both widely used for web applications, data storage, and other database tasks. They offer similar features, and MariaDB is often see
5 min read
How to Install SQL Developer in Linux?
SQL Developer is a client application or a desktop application. We can install it in our local system & can access Oracle Database. Oracle provides it. Oracle has a server component & SQL Developer has a client component. By using SQL developer we can access the Oracle database. SQL Developm
3 min read
How to Install Nose 2 in Python on Linux?
Nose 2 is a successor of the Nose package. It is used for testing Python applications. It provides different types of methods, modules, classes, test case levels, etc. It also provides built-in plugins which fulfill the specific need of the developer like tests coverage, profiling, etc. In this arti
2 min read