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.
How to Install and Setup Lua in Linux
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.
Contact Us