LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 314 min read

Installing Lua & Running Scripts

Install Lua on your system, use the interactive interpreter, run script files, and get familiar with the LuaRocks package manager.

Introduction

Because Lua is small and portable, getting it running on your machine takes only a couple of minutes. This lesson covers installing Lua on the major operating systems, using its interactive interpreter, running script files, and installing third-party libraries with LuaRocks.

What You Will Learn
  • How to install Lua on Windows, macOS, and Linux.
  • How to use the interactive Lua interpreter for quick experiments.
  • How to run a .lua script file from the command line.
  • What LuaRocks is and how to install a third-party library with it.

Installing Lua

The quickest path on most systems is your operating system's own package manager.

# macOS (Homebrew)
brew install lua
# Ubuntu/Debian
sudo apt install lua5.4
# Windows (via winget)
winget install DEVCOM.Lua
Terminal Output

Click Run to see what this code prints.

You can confirm the install worked, and check the exact version, with a single flag.

lua -v
Terminal Output

Click Run to see what this code prints.

The Interactive Interpreter

Running lua with no arguments drops you into an interactive prompt (a REPL — read-eval-print loop), perfect for quick experiments without creating a file.

lua
Interactive Session

Click Run to see what this code prints.

Running a Script File

For anything beyond a one-liner, save your code in a file with a .lua extension and pass it to the lua interpreter.

-- greet.lua
local name = "World"
print("Hello, " .. name .. "!")
lua greet.lua
Terminal Output

Click Run to see what this code prints.

The .. operator concatenates strings — the first specific piece of Lua syntax you'll use constantly starting from the very next lesson.

LuaRocks: The Package Manager

LuaRocks is Lua's de facto package manager, similar in role to pip for Python or npm for JavaScript — it installs and manages third-party Lua libraries ("rocks").

# Install LuaRocks itself (varies by OS -- shown here for macOS/Homebrew)
brew install luarocks
# Install a library, e.g. a JSON encoder/decoder
luarocks install dkjson
Terminal Output

Click Run to see what this code prints.

Common Mistakes

Avoid These Mistakes
  • Confusing lua (the interpreter) with luac (Lua's bytecode compiler) — you'll use lua directly for nearly everything in this course.
  • Not checking which Lua version a package manager installs by default — some systems still default to an older 5.1 build.
  • Forgetting the -- for comments (not // or #) — a very common early mistake coming from other languages.

Best Practices

  • Confirm your installed version with lua -v before assuming a specific 5.3/5.4-only feature is available.
  • Keep a scratch.lua file around for quick experiments instead of relying purely on the interactive REPL for longer snippets.
  • Install LuaRocks early — even this course's later lessons on modules will make more sense once you've seen a real installed library.

Frequently Asked Questions

No — every example in this course uses only Lua's built-in standard library. LuaRocks is introduced here so you know it exists once you start building real projects.

LuaJIT is a separate, alternative implementation focused on extreme performance via just-in-time compilation, targeting Lua 5.1 semantics — you'd install it separately if a project specifically calls for it.

Yes — the official Lua website hosts a "Try Lua" online interpreter (lua.org, and also the community site tio.run) where you can run snippets directly in a browser.

Key Takeaways

  • Lua installs quickly through your OS package manager on Windows, macOS, and Linux.
  • Running lua with no file argument opens an interactive REPL for quick experiments.
  • A .lua script file runs with lua filename.lua from the command line.
  • LuaRocks is Lua's package manager for installing third-party libraries.

Summary

You now have a working Lua installation, know how to run both quick one-liners and full script files, and have seen how third-party libraries get installed. Next, you'll dig into Lua's variables and its small, dynamically typed set of data types.

Next Lesson →

Variables & Data Types