This guide covers how to install Lua on Arch Linux, including the latest Lua 5.4, LuaJIT for high-performance applications, and older versions for compatibility. Lua excels at embedded scripting, game development, and configuration where a lightweight interpreter with minimal footprint makes integration with C applications straightforward. Common use cases include game engines like Love2D and Roblox, web servers like Nginx with OpenResty, Neovim plugin development, and IoT devices where memory constraints matter. By the end, you will have working Lua interpreters, the LuaRocks package manager for extending Lua with community modules, and the ability to write and execute Lua scripts.
Update Arch Linux Before Installation
Synchronize package databases and upgrade installed packages before installing new software. Arch Linux is a rolling release distribution, meaning packages update continuously rather than in fixed releases. Running a system update ensures your package database reflects the latest available versions and prevents dependency conflicts during installation:
sudo pacman -Syu
The -Syu flags synchronize the package database (-y), then upgrade all installed packages to their latest versions (-u). On a fresh install or after some time away, this may download several hundred megabytes of updates.
Install Lua on Arch Linux
The official Arch Linux repositories provide multiple Lua versions. The main lua package contains the latest stable release, while versioned packages maintain compatibility with software requiring specific Lua versions.
| Package | Version | Binary Name | Best For |
|---|---|---|---|
| lua | Lua 5.4.x | lua | New projects, modern Lua features, most users |
| lua53 | Lua 5.3.x | lua5.3 | Applications requiring Lua 5.3 compatibility |
| lua52 | Lua 5.2.x | lua5.2 | Legacy applications, older game mods |
| lua51 | Lua 5.1.x | lua5.1 | LuaJIT compatibility, World of Warcraft addons |
| luajit | LuaJIT 2.1.x | luajit | High-performance applications, Neovim, OpenResty |
For most users, the lua package is recommended because it provides the latest stable release with modern features like integers, UTF-8 support, and improved garbage collection. Install versioned packages only when specific software requires them.
Install Lua 5.4 (Recommended)
Install the latest Lua version from the official repositories:
sudo pacman -S lua
Verify the installation by checking the version:
lua -v
Lua 5.4.8 Copyright (C) 1994-2025 Lua.org, PUC-Rio
Install LuaJIT for High Performance
LuaJIT is a Just-In-Time compiler that serves as a drop-in replacement for Lua 5.1 with significantly better performance. “Just-In-Time” means LuaJIT compiles Lua code to native machine code while your program runs, rather than interpreting it line by line. This approach gives LuaJIT performance approaching that of compiled C code for many workloads. Applications like Neovim, OpenResty (Nginx scripting), and mpv media player use LuaJIT for its speed advantages.
sudo pacman -S luajit
Verify the LuaJIT installation:
luajit -v
LuaJIT 2.1.1767980792 -- Copyright (C) 2005-2026 Mike Pall. https://luajit.org/
LuaJIT is API-compatible with Lua 5.1 and includes LuaJIT-specific extensions like the FFI (Foreign Function Interface) library for calling C functions directly from Lua without writing C wrapper code. Scripts written for Lua 5.1 generally run unchanged on LuaJIT, but scripts using Lua 5.2+ features (like integer division or goto statements) require standard Lua.
Install Multiple Lua Versions
Lua packages can coexist because each version installs to a separate binary name. Install additional versions as needed:
sudo pacman -S lua51 lua52 lua53
Each version uses a versioned binary name to avoid conflicts:
lua -v
lua5.1 -v
lua5.2 -v
lua5.3 -v
Lua 5.4.8 Copyright (C) 1994-2025 Lua.org, PUC-Rio Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio
Install Lua Modules on Arch Linux
Lua modules extend the language with additional functionality for JSON parsing, database access, web frameworks, and more. Arch Linux supports installing modules through both the system package manager and LuaRocks, the Lua-specific package manager.
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| Pacman | Arch Repos | Distribution default | Automatic via pacman -Syu | Most users who prefer tested, system-integrated packages |
| LuaRocks | luarocks.org | Latest stable | Manual via luarocks install | Developers needing modules not in repos or specific versions |
For most users, Pacman is recommended because it integrates with system updates and packages are tested for Arch Linux compatibility. Use LuaRocks when you need a module that is not available in the repositories or when you require a specific version.
Install Modules via Pacman
The official repositories contain pre-built Lua modules with the lua- prefix. Search for available modules:
pacman -Ss lua- | head -20
The output lists available modules (package names and versions vary as packages are updated):
extra/lua-dbi 0.7.4-1
Database interface library for Lua
extra/lua-filesystem 1.8.0-5
File system library for the Lua programming language
extra/lua-lpeg 1.1.0-3
Pattern-matching library for Lua
Install specific modules using pacman. For example, to install the filesystem and socket libraries:
sudo pacman -S lua-filesystem lua-socket
Common modules available in the official repositories:
lua-filesystem: File and directory operations beyond Lua’s built-in io librarylua-socket: Network support for TCP, UDP, HTTP, and SMTP protocolslua-lpeg: Parsing Expression Grammars for pattern matchinglua-sec: TLS/SSL bindings for secure network connectionslua-dbi: Database-independent interface for MySQL, PostgreSQL, and SQLitelua-dkjson: Pure Lua JSON encoding and decoding
Install LuaRocks Package Manager
LuaRocks provides access to thousands of Lua modules not available in the official repositories. Install it from pacman:
sudo pacman -S luarocks
LuaRocks depends on the lua package and automatically pulls it as a dependency. Verify the installation:
luarocks --version
/usr/sbin/luarocks 3.13.0 LuaRocks main command-line interface
Install Modules via LuaRocks
Search for modules on the LuaRocks repository:
luarocks search json
Install modules system-wide with sudo. The dkjson module provides pure-Lua JSON encoding and decoding:
sudo luarocks install dkjson
List installed modules:
luarocks list
Rocks installed for Lua 5.4 --------------------------- dkjson 2.8-2 (installed) - /usr/lib/luarocks/rocks-5.4
Verify the module works by importing it in Lua:
lua -e 'local json = require("dkjson"); print(json.encode({name="test", value=42}))'
{"name":"test","value":42}
JSON objects do not guarantee key ordering. Your output may show
{"value":42,"name":"test"}instead. Both are valid JSON representing the same data. If consistent ordering matters for your application, use dkjson’skeyorderoption.
Some LuaRocks modules require compilation. Install
base-develto ensure build tools are available:sudo pacman -S base-devel. Modules that depend on external C libraries may require additional packages likeopensslorlibffi.
Install Modules for Specific Lua Versions
LuaRocks defaults to the system Lua version (5.4), meaning modules install to Lua 5.4’s module path. If you have applications using older Lua versions, those applications cannot load modules installed for a different version because Lua keeps separate module directories for each major.minor release. To install modules for other Lua versions, use the --lua-version flag:
sudo luarocks --lua-version 5.1 install luasocket
The Arch Linux luarocks package is configured to work with Lua 5.4 by default. For intensive work with other Lua versions, consider installing version-specific LuaRocks packages from the AUR.
Test Your Lua Installation
Verify that Lua can interpret and execute code by creating a simple test script.
Use the Interactive Interpreter
Launch the Lua interactive shell:
lua
Test basic operations at the prompt:
print("Hello, World!")
print("Lua version: " .. _VERSION)
print("2 + 2 = " .. 2 + 2)
Hello, World! Lua version: Lua 5.4 2 + 2 = 4
Exit the interpreter by pressing Ctrl+D (sends end-of-file signal) or by typing os.exit() at the prompt.
Create a Test Script
Create a file named hello.lua:
nano hello.lua
Add the following Lua code:
#!/usr/bin/env lua
-- Display greeting and version information
print("Hello from Lua!")
print("Version: " .. _VERSION)
-- Demonstrate a simple function
local function greet(name)
return "Welcome, " .. name .. "!"
end
print(greet("Arch Linux user"))
-- Show table usage (Lua's primary data structure)
local system = {
os = "Arch Linux",
shell = os.getenv("SHELL") or "unknown",
user = os.getenv("USER") or "unknown"
}
print("\nSystem Information:")
for key, value in pairs(system) do
print(" " .. key .. ": " .. value)
end
The shebang line #!/usr/bin/env lua locates Lua in the system PATH, making the script portable. Save the file with Ctrl+O, press Enter, then exit with Ctrl+X.
Run the Script
Make the script executable and run it. The chmod +x command adds execute permission, allowing you to run the script directly like any other program:
chmod +x hello.lua
./hello.lua
Expected output:
Hello from Lua! Version: Lua 5.4 Welcome, Arch Linux user! System Information: os: Arch Linux shell: /bin/bash user: josh
Alternatively, run the script directly with the Lua interpreter without making it executable:
lua hello.lua
After testing, you can remove the test script if you no longer need it:
rm hello.lua
Test a Lua One-Liner
Lua supports one-liner execution with the -e flag for quick tasks:
lua -e 'for i=1,5 do print("Count: " .. i) end'
Count: 1 Count: 2 Count: 3 Count: 4 Count: 5
Troubleshooting
These solutions address the most common issues when working with Lua on Arch Linux, particularly around module paths and version mismatches.
Module Not Found After Installation
Error: A script fails with “module ‘name’ not found”.
lua: hello.lua:1: module 'dkjson' not found: no field package.preload['dkjson'] no file '/usr/share/lua/5.4/dkjson.lua'
Diagnostic: Check Lua’s module search paths:
lua -e 'print(package.path)'
lua -e 'print(package.cpath)'
Fix: Ensure the module is installed for the correct Lua version. LuaRocks installs modules for Lua 5.4 by default into /usr/lib/luarocks/rocks-5.4/. If you are running a script with lua5.1 or luajit, those interpreters look in different paths and cannot find modules installed for Lua 5.4. Reinstall the module with the appropriate version flag:
sudo luarocks --lua-version 5.1 install dkjson
LuaRocks Installation Fails with Compilation Errors
Error: Module installation fails with “gcc: command not found” or similar build errors.
Diagnostic: The module requires compilation but build tools are not installed.
Fix: Install the base development tools:
sudo pacman -S base-devel
For modules requiring specific libraries (like OpenSSL for lua-sec), install those dependencies first:
sudo pacman -S openssl
Wrong Lua Version Running
Error: Scripts or applications fail because the wrong Lua version is being used.
Diagnostic: Check which Lua binary is being invoked:
command -v lua
lua -v
Fix: Use the versioned binary name directly when a specific version is required:
lua5.1 script.lua
lua5.3 script.lua
luajit script.lua
For scripts requiring a specific version, update the shebang line:
#!/usr/bin/env lua5.1
LuaJIT-Specific Features Not Available
Error: Scripts using LuaJIT’s FFI library fail with “module ‘ffi’ not found” when run with standard Lua.
Diagnostic: The FFI library is LuaJIT-specific and not available in standard Lua.
Fix: Use LuaJIT to run scripts that require FFI or other LuaJIT extensions:
luajit script.lua
Alternatively, modify the script to check for FFI availability and provide a fallback for standard Lua.
Remove Lua from Arch Linux
If you installed LuaRocks, remove it first because it depends on the lua package. Attempting to remove lua while LuaRocks is installed will fail with a dependency error:
sudo pacman -Rns luarocks
Remove any additional Lua versions and LuaJIT you installed:
sudo pacman -Rns luajit lua51 lua52 lua53
Remove the main Lua package:
sudo pacman -Rns lua
The -Rns flags remove the package (-R), orphaned dependencies (-s), and configuration backup files (-n).
Verify removal:
pacman -Qi lua
error: package 'lua' was not found
Uninstalling LuaRocks removes modules in
/usr/lib/luarocks/. If you installed modules to a user directory with--local, those remain in~/.luarocks/and require manual removal withrm -rf ~/.luarocksif no longer needed.
Frequently Asked Questions
No, Lua is not pre-installed on the base Arch Linux system. You must install it manually with pacman -S lua. Some packages may pull in Lua as a dependency, so it may be present if you installed software like Neovim or mpv first.
Lua is the standard interpreter from lua.org, currently at version 5.4. LuaJIT is a Just-In-Time compiler that is compatible with Lua 5.1 and provides significantly better performance. LuaJIT also includes the FFI library for calling C functions directly. Use standard Lua for Lua 5.2+ features; use LuaJIT when performance is critical or when software specifically requires it.
Prefer pacman when a module is available in the official repositories (lua-* packages) because it integrates with system updates and is tested for Arch Linux. Use LuaRocks for modules not available in the repositories or when you need a specific version.
Yes, Arch Linux allows installing multiple Lua versions side by side. Each version uses a separate binary name: lua (5.4), lua5.3, lua5.2, lua5.1, and luajit. You can switch between them by calling the appropriate binary name directly.
Neovim uses LuaJIT as its embedded Lua interpreter. If you write Neovim plugins in Lua, you are writing for LuaJIT which is Lua 5.1 compatible with JIT extensions. The luajit package on Arch Linux provides the same LuaJIT version used by Neovim.
Conclusion
You now have Lua installed on Arch Linux with access to multiple interpreter versions, LuaRocks for extending Lua with community modules, and the ability to write and execute Lua scripts. For database-driven applications, connect to SQLite or PostgreSQL using the lua-dbi module, or automate deployment workflows by combining Lua scripts with Docker containers. For Neovim plugin development, LuaJIT extensions, and web application frameworks, refer to the Arch Wiki Lua documentation.