Install Lua on Linux

Installing Lua on Linux is straightforward using your distribution’s package manager. Most Linux distributions include Lua in their official repositories.

Using Package Managers

Ubuntu/Debian

For Ubuntu 20.04+ and Debian 10+:

sudo apt update
sudo apt install lua5.4

For older Ubuntu versions or if you prefer Lua 5.3:

sudo apt install lua5.3

CentOS/RHEL/Fedora

On Fedora:

sudo dnf install lua

On CentOS/RHEL:

sudo yum install lua

Arch Linux

sudo pacman -S lua

openSUSE

sudo zypper install lua

Verifying Installation

After installation, verify that Lua is installed correctly:

lua -v

You should see output similar to:

Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio

Testing Your Installation

Let’s test Lua with a simple script. Create a file called hello.lua:

nano hello.lua

Add this content:

print("Hello, Lua!")
print("Lua version:", _VERSION)

Run the script:

lua hello.lua

Installing Multiple Lua Versions

If you need multiple Lua versions installed simultaneously, you can use version-specific package names:

# Ubuntu/Debian example
sudo apt install lua5.3 lua5.4

Then run specific versions:

lua5.3 -v
lua5.4 -v

Installing from Source

If you need a specific version not available in your repository, or want to compile with custom options:

  1. Install build dependencies:
sudo apt install build-essential libreadline-dev
  1. Download and compile Lua:
wget https://www.lua.org/ftp/lua-5.4.4.tar.gz
tar xzf lua-5.4.4.tar.gz
cd lua-5.4.4
make linux test
sudo make install

This will install Lua to /usr/local/bin/lua.

Next Steps

Once Lua is installed, you can start learning the Lua basics or install LuaRocks to manage packages and libraries.

For more detailed installation options and troubleshooting, visit the official Lua documentation.

Last updated on