Installing Lua
Before writing any Lua code, you need a working Lua interpreter on your machine. The official distribution, available from lua.org, ships as source code that you compile yourself, since the Lua team does not publish official binaries for every platform. In practice, most developers install Lua through their operating system's package manager, a tool like Homebrew or apt, or a bundled distribution such as LuaJIT, which offers a compatible interpreter with a just-in-time compiler for faster execution.
Cricket analogy: Installing Lua from source versus a package manager is like a batsman choosing between building a bat from raw willow versus buying one ready-made from a store like SG or Kookaburra — both get you a working bat, but one requires more shaping effort upfront.
Installing on Linux, macOS, and Windows
On Debian- or Ubuntu-based Linux distributions, sudo apt install lua5.4 pulls a ready-to-use interpreter directly from the system repositories. On macOS, Homebrew makes this a one-line install with brew install lua, which also sets up LuaRocks-compatible paths. Windows users typically install Lua through a distribution like LuaBinaries, via the Chocolatey package manager with choco install lua, or by using Windows Subsystem for Linux (WSL) to get the same apt-based workflow as native Linux. Each of these routes produces a lua executable on your PATH, so the day-to-day experience of running scripts is identical regardless of which platform you installed on.
Cricket analogy: Getting the same 'lua' executable regardless of platform is like the LBW rule applying identically whether a Test match is played at Lord's, the MCG, or Eden Gardens — the underlying mechanism stays consistent no matter which ground (operating system) you're playing on.
Verifying Your Installation and Using the REPL
Once installed, confirm everything worked by running lua -v in a terminal, which prints the interpreter's version string, such as Lua 5.4.6. Running lua with no arguments drops you into the interactive REPL (read-eval-print loop), where you can type expressions like print(2 + 2) and see results immediately without saving a file. This is the fastest way to sanity-check syntax, inspect the behavior of a standard library function, or experiment with a table before committing it to a script. Exit the REPL with os.exit(), Ctrl-D on Unix-like systems, or Ctrl-Z followed by Enter on Windows.
Cricket analogy: Checking 'lua -v' before writing code is like a bowler checking the pitch report before a match — a quick verification step that confirms conditions are right before committing to a full over, rather than discovering a problem mid-delivery.
Installing LuaRocks, Lua's Package Manager
LuaRocks is the de facto package manager for Lua, letting you install reusable libraries — called 'rocks' — the way npm does for Node.js or pip does for Python. After installing Lua itself, install LuaRocks via your OS package manager (brew install luarocks, sudo apt install luarocks) or by building it from source, then use commands like luarocks install luasocket to pull networking libraries or luarocks install busted for a testing framework. LuaRocks respects Lua's version-specific module paths, so it's worth confirming with lua -v which Lua version you're targeting before installing rocks, since a rock built against Lua 5.1 won't necessarily load cleanly under Lua 5.4.
Cricket analogy: LuaRocks installing reusable libraries is like a franchise's support staff bringing in a specialist fielding coach for one tournament — you're adding a proven external resource to your existing squad rather than training that skill up from scratch.
# Debian/Ubuntu
sudo apt update
sudo apt install lua5.4 -y
# macOS (Homebrew)
brew install lua
# Windows (Chocolatey, run in an elevated shell)
choco install lua -y
# Verify the install
lua -v
# => Lua 5.4.6 Copyright (C) 1994-2023 Lua.org, PUC-Rio
# Install LuaRocks and a sample library
luarocks install luasocketPackage repositories sometimes lag behind the latest Lua release — Ubuntu LTS releases, for example, can ship Lua 5.3 or 5.4 depending on the version, so always run lua -v after installing and check it against the syntax you intend to use (like integer division //, added in 5.3) before assuming a feature is available.
- The official Lua distribution from lua.org ships as source; most developers install via a package manager instead.
- Linux:
sudo apt install lua5.4; macOS:brew install lua; Windows:choco install luaor WSL. lua -vprints the installed version and confirms the interpreter is on your PATH.- Running
luawith no file argument opens the interactive REPL for quick experimentation. - LuaRocks is Lua's package manager, installed separately, used to pull in libraries like luasocket or busted.
- Rocks are version-specific — a package built for Lua 5.1 may not load under Lua 5.4.
- LuaJIT is a popular alternative interpreter offering JIT-compiled performance, compatible with Lua 5.1 syntax.
Practice what you learned
1. Which command installs Lua on a Debian/Ubuntu system?
2. What does running `lua` with no arguments do?
3. What is LuaRocks?
4. Why might a rock fail to load even though Lua is installed correctly?
5. How do you exit the Lua REPL on a Unix-like system?
Was this page helpful?
You May Also Like
What Is Lua?
An introduction to Lua's history, design philosophy, and defining traits as a lightweight, embeddable scripting language.
Your First Lua Script
Write, run, and structure a small real Lua script, covering command-line execution, comments, print, and basic input.
Lua Types and Variables
How Lua's dynamic typing, variable scope, number/string types, and tables work, with the specifics that trip up newcomers.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics