How to Install, Set Up, And Get Started Coding With The Lua Programming Language - On Linux

A List For 2025

By Rob Rockwell

Lua is a lightweight, fast, and embeddable scripting language known for its small footprint and flexibility. Originally designed for embedded systems and games, Lua has found a home in everything from web servers and IoT devices to major game engines like Roblox and game frameworks like LÖVE. Its minimal syntax and powerful metaprogramming capabilities make it ideal for scripting environments where performance and simplicity are key.

Whether you're a developer looking to embed a scripting layer into your C/C++ project, or you're a beginner eager to learn your first programming language, Lua offers a clean and accessible starting point. In this guide, we’ll walk through how to install Lua on Linux, configure your development environment, run your first scripts, and begin using tools like LuaRocks to manage packages effectively.

Retro Mainframe Smiling Guy Install Lua

Lua Prerequisites

Before installing Lua, make sure your system has basic development tools like a C compiler (such as gcc) and make, as Lua is often compiled from source. On Ubuntu or other Debian-based systems, you can install these with:

sudo apt update sudo apt install build-essential

You may also need libreadline-dev if you want readline support in the Lua interpreter.

Installing Lua

On Ubuntu and similar distros, you can install Lua directly using apt:

sudo apt install lua5.4

This installs the Lua interpreter and basic tools. You can check the installed version with:

lua -v

If you want the latest version, consider downloading Lua from the official site (lua.org) and building it from source.

Using LuaRocks or Docker for Environment Management

LuaRocks is Lua’s package manager and a convenient way to install and manage Lua libraries. Install it via:

sudo apt install luarocks

You can then install packages like so:

luarocks install luasocket

Docker is another option for isolating Lua environments. You can run Lua in a container like this:

docker run -it lua

This gives you a clean, temporary Lua environment without needing to install anything on your host machine.

Verifying Your Installation

Once installed, you can verify that Lua is working correctly by checking the version:

lua -v

This should output something like Lua 5.4.6 or whatever version is installed. If the command runs successfully and shows a version number, your installation is good to go.

Setting Up LuaRocks for Package Management

LuaRocks is the most widely used package manager for Lua. On most systems, it's either installed alongside Lua or can be added easily:

sudo apt install luarocks

Once installed, you can verify it with:

luarocks --version

You can now install packages globally (or locally if needed):

luarocks install lua-cjson

Using the Lua Interpreter

The Lua interpreter provides a simple REPL (Read-Eval-Print Loop) where you can test code interactively. Just type:

lua

You’ll see the Lua prompt where you can enter expressions like:

print("Hello, Lua!")

Press Ctrl+D or type os.exit() to exit the REPL.

Writing Your First Lua Script

To write your first Lua script, create a new file with the `.lua` extension—let's call it hello.lua—and add the following line:

print("Hello, world!")

Save the file and run it using the Lua interpreter from your terminal:

lua hello.lua

If everything is working correctly, you should see the output: Hello, world!

Configuring Your Editor or IDE

Lua has broad support across popular editors. Lightweight editors like VS Code, Sublime Text, and Neovim work well with Lua syntax highlighting and linting.

For VS Code, install the "Lua" extension by Sumneko or another community-supported plugin to get features like autocompletion, inline documentation, and debugging support. Make sure your editor is configured to use spaces instead of tabs (Lua conventionally uses 2 spaces for indentation).

Creating a Basic Lua Project

A minimal Lua project might include a few `.lua` files and a README.md. You could also include a rockspec file if you’re using LuaRocks for package distribution.

For example, your structure might look like:

my-lua-project/ ├── init.lua ├── utils.lua ├── README.md └── rockspec

From here, you can use require("utils") in your init.lua file to pull in other Lua modules you've written.

Next Steps and Learning Resources

To deepen your Lua knowledge, start by exploring the official Lua documentation at lua.org/manual. The "Programming in Lua" book by Roberto Ierusalimschy is also a must-read.

You can also join Lua communities on Reddit (r/lua), the Lua mailing list, or Discord channels dedicated to game dev and scripting. And be sure to check out our Code Visualization course!

Start mastering programming with our revolutionary Code Visualization course!