Lua Setup Guide — Install Lua and Run Your First Script
In this tutorial, you will learn about Lua Setup Guide. We cover key concepts, practical examples, and best practices to help you master this topic.
Lua installation requires downloading the Interpreter, setting up the PATH, and verifying your setup with a simple script before diving into language features.
What You'll Learn
- Installing Lua on Linux, macOS, and Windows
- Running Lua scripts from the command line
- Using the Lua REPL for interactive exploration
- Setting up a development environment with editors and tools
Why It Matters
A proper Lua setup ensures you can test scripts quickly, access the standard libraries, and eventually compile LuaJIT or embed Lua in C applications. Doda Browser uses Lua for plugin scripting, and Durga Antivirus Pro runs Lua sandboxes for threat rules -- both require correct Lua runtime configuration.
Real-World Use
Game developers install Lua alongside game engines like Love2D or Defold. System administrators embed Lua in Nginx/OpenResty. Each use case needs a properly configured Lua environment with the correct version and libraries.
flowchart LR
A["Setup"] --> B["Install"]
B --> C["REPL"]
C --> D["First Script"]
D --> E["Editor Config"]
A:::current --> B
style A fill:#2563eb,stroke:#2563eb,color:#fff
style B fill:#dbeafe,stroke:#2563eb,color:#1e40af
style C fill:#dbeafe,stroke:#2563eb,color:#1e40af
style D fill:#dbeafe,stroke:#2563eb,color:#1e40af
style E fill:#f1f5f9,stroke:#94a3b8,color:#64748b
Installing Lua
Linux
# Debian/Ubuntu
sudo apt update
sudo apt install lua5.4
# Fedora
sudo dnf install lua
# Arch
sudo pacman -S lua
# Verify
lua -v
Expected output:
Lua 5.4.7 Copyright (C) 1994-2024 Lua.org, PUC-Rio
macOS
# Using Homebrew
brew install lua
# Verify
lua -v
Windows
Download the Lua binaries from lua.org/download.html or use winget:
winget install Lua.Lua
Alternatively, use Lua for Windows which bundles Lua with useful libraries and a SciTE editor.
Using the Lua REPL
The Lua REPL (Read-Eval-Print Loop) lets you type Lua code and see results immediately.
lua
> print("Hello from REPL!")
Hello from REPL!
> 2 + 2
4
> _VERSION
Lua 5.4
> os.date()
Sun Jun 28 12:00:00 2026
> os.exit()
Type os.exit() or press Ctrl+D to quit the REPL.
Running Lua Scripts
Create a file called hello.lua:
-- hello.lua
print("Hello, Lua!")
print("Version: " .. _VERSION)
print("Date: " .. os.date())
Run it:
lua hello.lua
Expected output:
Hello, Lua!
Version: Lua 5.4
Date: Sun Jun 28 12:00:00 2026
You can also run Lua without saving a file:
lua -e 'print("Hello from -e flag!")'
Editor Setup
VSCode
Install the Lua extension by sumneko. It provides:
- Syntax highlighting
- Code completion
- Diagnostics and linting
- Go to definition
ZeroBrane Studio
A lightweight Lua IDE with a visual debugger, integrated LuaJIT support, and Love2D project templates. Good for beginners.
Vim/Neovim
Basic Lua support is built-in. For enhanced features, use the lua-language-server with coc.nvim or native LSP.
LuaRocks
LuaRocks is the package manager for Lua. It handles dependencies and installs modules.
# Install LuaRocks
sudo apt install luarocks
# Verify
luarocks --version
# Install a package
luarocks install luasocket
Common Mistakes
1. Installing wrong version
Some projects require Lua 5.1 (LuaJIT) while others use Lua 5.4. Check which version your project needs before installing.
2. Forgetting os.exit() in REPL
The REPL doesn't quit with Ctrl+C on some systems. Use os.exit() or Ctrl+D.
3. Not installing LuaRocks
LuaRocks is essential for managing dependencies. Without it, you'll manually download and configure libraries.
4. Ignoring lua vs luajit commands
Standard Lua and LuaJIT are separate executables. lua runs standard Lua 5.4; luajit runs LuaJIT (5.1 compatible).
5. Using Windows line endings
Lua scripts with CRLF line endings can cause issues with shebang lines on Linux. Use LF line endings.
Practice Questions
1. How do you check which Lua version is installed?
Run lua -v or check _VERSION in the REPL.
2. What is the Lua REPL and how do you access it?
The REPL is an interactive Lua shell. Type lua in the terminal to enter it.
3. What is LuaRocks and why is it important? LuaRocks is the Lua package manager. It installs Lua modules and handles dependencies, similar to Python's pip or npm.
Challenge: Install Lua 5.4, create a script that prints "Setup complete" along with the current date and time, and run it from the command line.
FAQ
{{< faq question="Do I need LuaJIT or standard Lua?" >}} For learning, start with standard Lua 5.4. For Game Development (Love2D) or performance-critical code, use LuaJIT. Some projects require Lua 5.1 compatibility which LuaJIT provides. {{< /faq >}}
{{< faq question="Can I use Lua in my browser?" >}} Yes. Lua can run in the browser via projects like Fengari (a Lua VM compiled to JS) or lua.vm.js. This is useful for interactive documentation and online playgrounds. {{< /faq >}}
{{< faq question="What IDE should I use for Lua?" >}} ZeroBrane Studio is purpose-built for Lua. VSCode with sumneko's Lua extension is excellent. For Love2D, ZeroBrane has built-in support. {{< /faq >}}
{{< faq question="How do I uninstall Lua?" >}}
On Linux: sudo apt remove lua5.4. On macOS: brew uninstall lua. On Windows: use Add/Remove Programs or winget uninstall Lua.Lua.
{{< /faq >}}
{{< faq question="Does Lua have a debugger?" >}}
Yes. ZeroBrane Studio includes a visual debugger with breakpoints, watches, and step-through. Command-line debugging is available via luac -l for bytecode inspection and MobDebug for remote debugging.
{{< /faq >}}
Try It Yourself
lua -e '
print("OS: " .. os.time())
print("Dir: " .. os.date())
for i = 1, 3 do
print("Line " .. i)
end
'
Expected output:
OS: 1719576000
Dir: Sun Jun 28 12:00:00 2026
Line 1
Line 2
Line 3
What's Next
With Lua installed and your first script running, proceed to learn the syntax fundamentals -- variables, types, and operators.
| Topic | Description | Link |
|---|---|---|
| Syntax | Variables, types, operators | {{< ref "03-syntax" >}} |
| Tables | Lua's universal data structure | {{< ref "04-tables" >}} |
| Python Setup | Compare with Python installation | Python |
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro