luaguides

Installing Lua on Windows, macOS, and Linux

Lua is a lightweight, fast scripting language used in everything from game development (Roblox, LÖVE) to embedded systems and configuration files. Installing Lua takes just a few minutes regardless of your operating system, and this guide walks you through every step — from picking the right package manager to verifying your setup and running your first script. No prior programming experience is needed.

This guide covers installation on Windows, macOS, and Linux, plus how to verify everything works and write a simple program to confirm your environment is ready.

Prerequisites

You need a computer running Windows 10 or later, macOS 10.14 or later, or any modern Linux distribution. For the macOS instructions, you will use Homebrew — if Homebrew is not already installed, the guide shows you how to set it up first. For Windows, you can choose between the official installer or the Scoop package manager. For Linux, any distribution with a standard package manager (apt, dnf, pacman) works, and the source-build instructions cover distributions that ship older Lua versions.

Installing Lua on macOS

The easiest way to install Lua on macOS is through Homebrew, the package manager for macOS. Homebrew handles the entire process: it downloads the Lua source, compiles it for your machine’s architecture, and installs the binary into /usr/local/bin (or /opt/homebrew/bin on Apple Silicon). The brew install lua command pulls the latest stable release — currently Lua 5.4.7 — and also installs any required build dependencies like readline for the interactive REPL.

Install Homebrew (if you have not already)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Lua via Homebrew

Once Homebrew is installed, installing Lua takes one command. The package name is simply lua, and Homebrew resolves it to the latest stable version automatically. If you need a specific version like Lua 5.3, you can use brew install lua@5.3 instead.

brew install lua

This installs the latest stable version of Lua (currently Lua 5.4). The Homebrew formula pulls a pre-compiled binary for your architecture (Intel or Apple Silicon) and places it alongside the standard library modules. If you need LuaRocks — the Lua package manager — you can also brew install luarocks to get it in one step.

Verify the installation

Check that Lua is installed correctly by querying its version. The output shows the Lua version number, copyright line, and the publisher (PUC-Rio). If you see “command not found,” close and reopen your terminal — on some macOS setups, Homebrew’s binary path is added to $PATH during shell initialization, which only takes effect in new terminal sessions.

lua -v

You should see output like:

Lua 5.4.7  Copyright (C) 1994-2024 Lua.org, PUC-Rio

Getting Lua on Windows

On Windows, you have two main options: the official installer or Scoop (a command-line installer). The official installer is simpler if you prefer a GUI-driven process — you download a .exe file, click through the wizard, and Lua gets added to your system PATH automatically. Scoop is better if you want to manage Lua alongside other developer tools from the command line, similar to how brew works on macOS.

Option 1: official installer

  1. Visit the Lua downloads page
  2. Download the Windows installer (look for “LuaBinaries” → “Windows Lua binaries”)
  3. Run the installer and follow the prompts

After installation, open PowerShell or Command Prompt and verify. The installer places lua.exe in a directory that gets added to your system PATH, so you can run lua from any terminal. If the command is not recognized, try restarting your terminal or, on older Windows versions, logging out and back in to refresh the PATH environment variable.

lua -v

Option 2: using Scoop

If you prefer a package manager approach, Scoop works well on Windows. Scoop installs programs into your user directory (~/scoop/) rather than requiring administrator privileges, which is safer and avoids polluting the system PATH. The scoop install lua command downloads the official Lua binaries and sets up shims so that lua works from any terminal. Scoop also makes it easy to switch versions later with scoop update lua, and you can install complementary tools like luarocks with a single command:

# Install Scoop (run in PowerShell)
iwr -useb get.scoop.sh | iex

# Install Lua
scoop install lua

Verify with:

lua -v

Getting Lua on Linux

Most Linux distributions include Lua in their package repositories. The package names vary slightly between distributions: Ubuntu uses lua5.4, Fedora uses lua, and Arch uses lua. Installing through your distribution’s package manager is the recommended approach — it handles dependency resolution, gets security updates through your normal update workflow, and puts the Lua binary on your PATH automatically.

Ubuntu and Debian

sudo apt update
sudo apt install lua5.4

The base package gives you the Lua interpreter and standard library. If you want to compile C modules that link against Lua — for example, when installing libraries like LuaFileSystem or LPeg from source — you also need the development headers and the static library. Install both the runtime and development packages in one step:

sudo apt install lua5.4 liblua5.4-dev

Fedora

On Fedora, the package is simply named lua and dnf resolves it to the latest version available in the Fedora repositories. Fedora tends to track Lua releases closely, so you typically get the current stable version within weeks of upstream release:

sudo dnf install lua

Arch Linux

Arch follows a rolling release model, so pacman -S lua always pulls the latest Lua release from the Arch repositories. The package includes the interpreter, compiler (luac), and standard libraries. For development headers, install lua and the files are included automatically — Arch does not split runtime and development packages:

sudo pacman -S lua

Building from source (any Linux distribution)

For the latest features or if you need a specific version, building from source gives you full control. The Lua source distribution is small — the tarball is under 400KB — and compiles in seconds on modern hardware. The make linux target builds the interpreter, the compiler (luac), and the standard libraries. The make install step copies the binaries to /usr/local/bin and the headers to /usr/local/include, so you may need sudo if your user does not own those directories. You can also pass INSTALL_TOP=$HOME/local to install into your home directory without root, and the Makefile supports make test to run the Lua test suite before installing:

# Download Lua source
curl -R -O https://www.lua.org/ftp/lua-5.4.7.tar.gz

# Extract and build
tar zxf lua-5.4.7.tar.gz
cd lua-5.4.7
make linux
sudo make install

Verify with a version check. The source build typically installs to /usr/local/bin/lua, which should take precedence over any system-packaged Lua in /usr/bin/ if /usr/local/bin appears first in your PATH:

lua -v

Running your first Lua script

Now that Lua is installed, let us write and run your first script. This will confirm that the Lua interpreter can find and execute your code, and it gives you a quick tour of basic Lua syntax — variables, arithmetic, string concatenation, and loops — all in a single file.

Create a simple script

Create a file called hello.lua with your favorite text editor. The script demonstrates several Lua fundamentals at once: comments start with --, variables are declared with local (which limits their scope to the current block), arithmetic uses standard operators, string concatenation uses .. (two dots, not + like in JavaScript or Python), and numeric for loops follow the syntax for var = start, end do ... end with 1-based counting.

-- hello.lua
print("Hello, Lua!")

-- Let's do some basic math
local x = 10
local y = 20
local sum = x + y

print(x .. " + " .. y .. " = " .. sum)

-- A simple loop
for i = 1, 3 do
    print("Counting: " .. i)
end

Run the script

Execute it from your terminal. The lua command takes the filename as its argument and runs the script in the Lua interpreter. If your file is in a different directory, provide the full path. The output should match exactly what you expect — Lua prints to standard output by default, so the results appear in your terminal window. Run this command from the same directory where you saved hello.lua:

lua hello.lua

You should see:

Hello, Lua!
10 + 20 = 30
Counting: 1
Counting: 2
Counting: 3

Interactive mode

You can also run Lua interactively by typing lua without a file. This opens the Lua REPL (Read-Eval-Print Loop), which evaluates each line of Lua code as you type it and prints the result. The REPL is useful for quick experiments, testing one-off expressions, and exploring the standard library without creating a file. Press Ctrl+D on macOS/Linux or Ctrl+Z followed by Enter on Windows to exit.

lua

This opens the Lua REPL (Read-Eval-Print Loop). Type Lua code and press Enter to execute it immediately. Press Ctrl+D (or Ctrl+Z on Windows) to exit.

Choosing your Lua version

Lua has several versions in active use, and the right choice depends on your project:

  • Lua 5.4 — The latest stable version (5.4.7). Best for new projects.
  • Lua 5.3 — Still widely used, particularly in embedded systems.
  • LuaJIT — A Just-In-Time compiler with excellent performance. Used in many game engines and high-performance applications.

Most beginners should start with Lua 5.4. If you need LuaJIT (for Roblox development you use Luau, a Lua derivative), check your specific platform’s requirements. LuaJIT tracks Lua 5.1 syntax with some 5.2 extensions, so code written for Lua 5.4 may not run under LuaJIT without adjustments — notably, LuaJIT lacks the integer subtype and the goto statement behaves differently.

Troubleshooting common issues

”Command not found” or “lua is not recognized”

  • Ensure the Lua binary directory is in your PATH
  • On Windows, you may need to restart your terminal or computer after installation
  • Try finding the lua executable: where lua (Windows) or which lua (macOS/Linux)

Permission denied errors on Linux

If you get permission errors when running sudo make install, make sure you have sudo privileges or the appropriate permissions. On shared systems where you do not have sudo access, you can install Lua locally by passing a prefix to make install:

make linux
make install INSTALL_TOP=$HOME/local

Then add $HOME/local/bin to your PATH in your shell configuration file.

Version Mismatch

Some systems have multiple Lua versions installed. This is common on Linux where both lua5.3 and lua5.4 packages coexist, or on macOS where Homebrew’s lua might shadow a system-provided version. Use lua5.4 or lua5.3 to specify a version explicitly, or check which version is the default:

lua -v

If you need to switch between versions, use your package manager to set the default. On Debian-based systems, update-alternatives --config lua-interpreter lets you pick which version lua points to.

Understanding what Lua is

Lua is a powerful, efficient, lightweight scripting language designed for extending applications. It was created in 1993 at the Pontifical Catholic University of Rio de Janeiro in Brazil, and has grown to become one of the most popular scripting languages for game development and embedded use.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. It is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection.

Key characteristics that make Lua popular include its small footprint — the entire interpreter is under 300KB, making it ideal for embedded systems. LuaJIT can match the performance of compiled languages in many benchmarks. The C API makes it simple to add scripting to any C or C++ application, and Lua runs on virtually any platform that has a C compiler.

Understanding these basics helps you appreciate why Lua is the language of choice for many developers when they need a fast, embeddable scripting solution.

Next steps

Now that Lua is installed and verified, you are ready to start programming. The next tutorial in this series covers variables and types — how Lua handles numbers, strings, booleans, nil, and tables, and the important distinction between nil and “no value.” You will also learn about Lua’s dynamic typing system and how it differs from statically typed languages you may have used before.

See also