A comprehensive guide to setting up a complete Lua development environment on Windows with native compilation support for LuaRocks packages.
Setting up Lua development on Windows with native compilation capabilities is notoriously complex. You need:
- Working Lua interpreter
- LuaRocks package manager
- Native compiler (MinGW-w64) for compiling Lua rocks with C extensions
- Proper environment configuration
This guide walks through the complete setup process and common pitfalls.
- Windows 10/11
- Administrator privileges (for some installations)
- PowerShell
-
Download Tools Executable
- Go to LuaBinaries - Tools Executables
- Download
lua-5.4.2_Win64_bin.zip
-
Download Static Windows Libraries
- Go to LuaBinaries - Windows Libraries - Static
- Download
lua-5.4.2_Win64_mingw6_lib.zip
-
Extract and Install
# Create Lua directory mkdir C:\Lua54Extract both zips to
C:\Lua54\, you should have:lua54.exe,lua54.dll,luac54.exe,liblua54.aand aninclude\folder# Rename lua54.exe to lua.exe for convenience Rename-Item C:\Lua54\lua54.exe lua.exe # Rename luac54.exe to luac.exe for convenience Rename-Item C:\Lua54\luac54.exe luac.exe
-
Add to
PATHAdd
C:\Lua54to your systemPATHenvironment variable. -
Verify Installation
lua -v # Should output: Lua 5.4.2 Copyright (C) 1994-2020 Lua.org, PUC-Rio
LuaRocks needs a native compiler for packages with C extensions.
-
Install MSYS2
- Download from msys2.org
- Run installer with default settings
- Install to
C:\msys64
-
Install MinGW-w64 Toolchain
# In MSYS2 terminal pacman -S mingw-w64-ucrt-x86_64-gcc -
Add MinGW to Windows PATH
Add
C:\msys64\ucrt64\binto your systemPATHenvironment variable. -
Verify Compiler
gcc --version # Should show gcc version information
-
Download LuaRocks for Windows
- Go to LuaRocks releases
- Download
luarocks-3.x.x-windows-64.zip
-
Extract and Install
Extract to
C:\Lua54,luarocks.exeshould be inC:\Lua54\ -
Verify LuaRocks
luarocks --version # Should show LuaRocks version information
Set up the complete environment for Lua development:
-
Apply LuaRocks Environment
Add the following to your users environment variables:
- Add
%APPDATA%\luarocks\bintoPATH - Set
LUA_PATHandLUA_CPATHenvironment variables fromluarocks pathoutput
- Add
-
Test Basic Lua
lua -e "print('Hello, Lua!')"
-
Test LuaRocks
luarocks list
-
Test Native Compilation
# Try installing a package that requires compilation luarocks install luafilesystemIf successful, you'll see compilation output like:
x86_64-w64-mingw32-gcc -O2 -c -o src/lfs.o -IC:\Lua54/include src/lfs.c
-
Test Installed Package
lua -e "require('lfs'); print('LFS loaded successfully')"
C:\Lua54\
├── lua.exe # Lua interpreter
├── luac54.exe # Lua compiler
├── lua54.dll # Lua library
├── liblua54.a # Static library for compilation
├── luarocks.exe # LuaRocks package manager
└── include\ # Lua header files (if included)
C:\msys64\
├── ucrt64\bin\ # MinGW-w64 compiler tools
│ ├── gcc.exe
│ ├── x86_64-w64-mingw32-gcc.exe
│ └── ...
└── ...
# User directories
%APPDATA%\luarocks\
├── bin\ # Installed Lua scripts
├── lib\ # Installed Lua libraries
└── ...- Install MSYS2 First: Set up the compiler environment before LuaRocks
- Check PATH Order: Ensure your Lua installation comes before any other Lua in PATH
- Verify Each Step: Test each component individually before proceeding
- Use PowerShell: It handles path escaping better than Command Prompt
After complete setup, you should have:
# PATH should include:
C:\Lua54
C:\msys64\ucrt64\bin
%APPDATA%\luarocks\bin
# LUA_PATH and LUA_CPATH should be set according to:
luarocks pathThis setup provides a complete Lua 5.4 development environment on Windows with native compilation support for LuaRocks packages. The key is getting all the components properly configured and in the right order in your PATH.