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.4For older Ubuntu versions or if you prefer Lua 5.3:
sudo apt install lua5.3CentOS/RHEL/Fedora
On Fedora:
sudo dnf install luaOn CentOS/RHEL:
sudo yum install luaArch Linux
sudo pacman -S luaopenSUSE
sudo zypper install luaVerifying Installation
After installation, verify that Lua is installed correctly:
lua -vYou should see output similar to:
Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-RioTesting Your Installation
Let’s test Lua with a simple script. Create a file called hello.lua:
nano hello.luaAdd this content:
print("Hello, Lua!")
print("Lua version:", _VERSION)Run the script:
lua hello.luaInstalling 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.4Then run specific versions:
lua5.3 -v
lua5.4 -vInstalling from Source
If you need a specific version not available in your repository, or want to compile with custom options:
- Install build dependencies:
sudo apt install build-essential libreadline-dev- 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 installThis 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.