How to Install Lua on Ubuntu 26.04, 24.04 and 22.04

Install Lua on Ubuntu 26.04, 24.04, and 22.04 with APT or a checksum-verified source build. Covers LuaRocks, updates, and removal.

PublishedAuthorJoshua JamesRead time7 minGuide typeUbuntu

Lua works well when you need a small scripting language for plugin systems, configuration logic, game tooling, and lightweight automation. To install Lua on Ubuntu, most systems should start with the versioned APT packages because they receive normal package-manager updates and keep multiple Lua branches available side by side.

Ubuntu 26.04 includes a Lua 5.5 package, while Ubuntu 24.04 and 22.04 use Lua 5.4 as the newest packaged branch. If you need the newest upstream release or a pinned upstream version across supported Ubuntu releases, the GitHub release method builds Lua from the current release list, verifies the matching Lua.org checksum, and installs it as lua-github so it does not replace Ubuntu-owned commands.

Install Lua on Ubuntu

Choose the APT method unless your project specifically needs a newer upstream release than your Ubuntu version packages. The GitHub source method is useful for testing Lua 5.5 on Ubuntu 24.04 or 22.04, pinning a project to a specific stable release, or keeping an upstream build separate from distro packages.

Choose the Lua Installation Method on Ubuntu

MethodSourceBest ForUpdate Behavior
APT packagesUbuntu repositories, including the Lua 5.5 and Lua 5.4 package familiesMost users, system scripts, package-managed development, and compatibility testing across branchesapt upgrades
GitHub source helperLua GitHub Releases plus the matching Lua.org source archive checksumNewest stable upstream Lua, pinned upstream releases, and testing the same release on different Ubuntu versionsRerun install-lua-github manually

APT packages are easier to maintain and should be the default choice for servers and workstations. Use the GitHub helper only when the upstream release is part of your project requirement, because it compiles Lua locally and places the result under /usr/local/lua-github.

Update Ubuntu Before Installing Lua

Refresh your package index before installing Lua packages from Ubuntu repositories:

sudo apt update

The package and source-build steps use sudo for system paths. Configure sudo first if your user cannot elevate privileges; the related Ubuntu walkthrough is adding a user to sudoers on Ubuntu.

Check Lua Package Availability on Ubuntu

Ubuntu packages Lua by branch rather than through a generic lua package name. Versioned commands such as lua5.4 and lua5.5 are also safer in scripts because installing multiple branches can change the alternatives-managed /usr/bin/lua command.

Ubuntu ReleaseNewest Packaged Lua BranchOther Common Lua Packages
Ubuntu 26.04lua5.5lua5.4, lua5.3, lua5.2, lua5.1, luajit, luarocks, liblua5.5-dev, liblua5.4-dev
Ubuntu 24.04lua5.4lua5.3, lua5.2, lua5.1, luajit, luarocks, liblua5.4-dev
Ubuntu 22.04lua5.4lua5.3, lua5.2, lua5.1, luajit, luarocks, liblua5.4-dev

Many Lua branch packages live in Ubuntu’s universe component. If apt cannot find a package on a minimal system, enable the component first with the separate guide to enable Universe and Multiverse on Ubuntu, then refresh the package index again.

Install Lua with APT

Install the newest packaged Lua branch on Ubuntu 26.04 with this package:

sudo apt install lua5.5

Install the newest packaged Lua branch on Ubuntu 24.04 or 22.04 with this package:

sudo apt install lua5.4

On Ubuntu 26.04, verify the packaged Lua 5.5 branch with its versioned command:

lua5.5 -v
Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio

On Ubuntu 24.04 or 22.04, verify the packaged Lua 5.4 branch instead:

lua5.4 -v
Lua 5.4.6  Copyright (C) 1994-2023 Lua.org, PUC-Rio

Ubuntu 22.04 reports Lua 5.4.4. If you install the Lua 5.4 compatibility branch on Ubuntu 26.04, that release reports Lua 5.4.8.

Install Lua Compatibility Packages

Install older Lua branches when you maintain scripts or modules that are not ready for Lua 5.4 or 5.5:

sudo apt install lua5.4 lua5.3 lua5.2 lua5.1

On Ubuntu 26.04, add lua5.5 when you want the packaged current branch installed beside the compatibility branches:

sudo apt install lua5.5 lua5.4 lua5.3 lua5.2 lua5.1

Use explicit commands in scripts and build instructions after installing multiple branches:

lua5.4 -e 'print(_VERSION)'
lua5.3 -e 'print(_VERSION)'
Lua 5.4
Lua 5.3

Install LuaJIT on Ubuntu

Install LuaJIT when your application depends on the LuaJIT runtime or Lua 5.1 compatibility:

sudo apt install luajit

Verify the runtime with its dedicated command:

luajit -v
LuaJIT 2.1.1761786044 -- Copyright (C) 2005-2025 Mike Pall. https://luajit.org/

Ubuntu 24.04 and 22.04 print older LuaJIT build identifiers, so treat the banner as release-specific when the command succeeds.

Install Lua Development Headers on Ubuntu

Install development headers when compiling C modules, embedding Lua in a C application, or building software that links against Lua:

sudo apt install liblua5.4-dev

Ubuntu 26.04 also provides Lua 5.5 development headers:

sudo apt install liblua5.5-dev

Confirm that the header package owns the expected include file:

dpkg -S /usr/include/lua5.4/lua.h
liblua5.4-dev:amd64: /usr/include/lua5.4/lua.h

For Lua 5.5 headers on Ubuntu 26.04, check the matching include path:

dpkg -S /usr/include/lua5.5/lua.h
liblua5.5-dev:amd64: /usr/include/lua5.5/lua.h

Install Lua from GitHub Releases on Ubuntu

The GitHub method builds Lua from a stable release tag and installs it under a managed prefix. It downloads the release archive from Lua.org because the official FTP index publishes SHA-256 checksums for the source tarballs, then exposes the build as /usr/local/bin/lua-github and /usr/local/bin/luac-github.

Install Source Build Prerequisites

Install the compiler, build tools, certificates, and download client required by the helper:

sudo apt install build-essential curl ca-certificates

The build-essential package provides GCC and Make, while the curl command in Linux handles release checks and downloads. For a broader compiler setup, use the separate guide to install GCC on Ubuntu.

Create the Lua GitHub Install Helper

The helper reads the stable release list from GitHub, asks which release to install, verifies the Lua.org SHA-256 checksum, builds Lua, and updates a current symlink only after the install succeeds. It keeps versioned releases under /usr/local/lua-github/releases/, so a failed rebuild can roll back to the previous source-built Lua release.

sudo tee /usr/local/bin/install-lua-github > /dev/null <<'SCRIPT_EOF'
#!/usr/bin/env bash
set -euo pipefail

RELEASE_API="https://api.github.com/repos/lua/lua/releases?per_page=20"
RELEASE_PAGE="https://github.com/lua/lua/releases"
LUA_FTP_INDEX="https://www.lua.org/ftp/"
INSTALL_ROOT="/usr/local/lua-github"
CURRENT_LINK="${INSTALL_ROOT}/current"
BUILD_DIR="${HOME}/lua-github-source-build"

if [ "$(id -u)" -eq 0 ]; then
    echo "Run this command as a regular user; it uses sudo only for installation steps."
    exit 1
fi

for cmd in curl tar make gcc grep sed awk sha256sum sudo; do
    if ! command -v "$cmd" >/dev/null 2>&1; then
        echo "Error: $cmd is required but not installed."
        echo "Install prerequisites with: sudo apt install build-essential curl ca-certificates"
        exit 1
    fi
done

for link in /usr/local/bin/lua-github /usr/local/bin/luac-github; do
    if [ -e "$link" ] && [ ! -L "$link" ]; then
        echo "Error: $link exists and is not a symlink."
        echo "Move or remove it before running this installer."
        exit 1
    fi
done

fetch_release_tags() {
    local api_response

    if command -v jq >/dev/null 2>&1 && api_response="$(curl -fsSL -H "Accept: application/vnd.github+json" -H "User-Agent: install-lua-github" "$RELEASE_API" 2>/dev/null)"; then
        printf '%s\n' "$api_response" | jq -r '[.[].tag_name | select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))] | .[]'
        return
    fi

    echo "GitHub API unavailable; falling back to the public GitHub Releases page." >&2
    curl -fsSL "$RELEASE_PAGE" |
        grep -Eo '/lua/lua/releases/tag/v[0-9]+\.[0-9]+\.[0-9]+' |
        sed 's#.*/##' |
        awk '!seen[$0]++'
}

echo "Checking Lua releases from GitHub..."
mapfile -t RELEASE_TAGS < <(fetch_release_tags)

if [ "${#RELEASE_TAGS[@]}" -eq 0 ]; then
    echo "Error: no stable Lua release tags were returned by GitHub."
    exit 1
fi

LATEST_TAG="${RELEASE_TAGS[0]}"
CURRENT_VERSION="missing"

if [ -x "${CURRENT_LINK}/bin/lua" ]; then
    CURRENT_VERSION="$("${CURRENT_LINK}/bin/lua" -v 2>&1 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | sed -n '1p' || true)"
    CURRENT_VERSION="${CURRENT_VERSION:-unknown}"
fi

echo "Current Lua GitHub install: $CURRENT_VERSION"
echo "Latest GitHub release:     $LATEST_TAG"
echo
echo "Available stable releases:"

max_items=10
for i in "${!RELEASE_TAGS[@]}"; do
    if [ "$i" -ge "$max_items" ]; then
        break
    fi
    printf '%2d) %s\n' "$((i + 1))" "${RELEASE_TAGS[$i]}"
done

printf 'Select a release number, press Enter for %s, or type q to quit: ' "$LATEST_TAG"
read -r selection

case "$selection" in
    "")
        SELECTED_TAG="$LATEST_TAG"
        ;;
    q|Q)
        echo "No changes made."
        exit 0
        ;;
    *[!0-9]*)
        echo "Error: enter a number from the list, press Enter, or type q."
        exit 1
        ;;
    *)
        index=$((selection - 1))
        if [ "$index" -lt 0 ] || [ "$index" -ge "${#RELEASE_TAGS[@]}" ] || [ "$index" -ge "$max_items" ]; then
            echo "Error: selection is outside the displayed release list."
            exit 1
        fi
        SELECTED_TAG="${RELEASE_TAGS[$index]}"
        ;;
esac

VERSION="${SELECTED_TAG#v}"
ARCHIVE="lua-${VERSION}.tar.gz"
DOWNLOAD_URL="https://www.lua.org/ftp/${ARCHIVE}"
RELEASE_DIR="${INSTALL_ROOT}/releases/${VERSION}"
STAGING_DIR="${INSTALL_ROOT}/releases/.${VERSION}.staging.$$"
BACKUP_DIR="${INSTALL_ROOT}/releases/.${VERSION}.previous.$$"

if [ "$CURRENT_VERSION" = "$VERSION" ]; then
    echo "Lua $VERSION is already installed through ${CURRENT_LINK}."
    exit 0
fi

echo "Selected Lua release: $SELECTED_TAG"
echo "Resolving SHA-256 checksum from lua.org..."
checksum_block="$(curl -fsSL "$LUA_FTP_INDEX" | grep -A3 -F "$ARCHIVE" || true)"
sha256="$(printf '%s\n' "$checksum_block" | grep -Eo '[0-9a-f]{64}' | sed -n '1p' || true)"

if [ -z "$sha256" ]; then
    echo "Error: could not find a SHA-256 checksum for $ARCHIVE on lua.org."
    exit 1
fi

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
rm -rf "lua-${VERSION}" "$ARCHIVE"

echo "Downloading $ARCHIVE..."
curl -fLO --progress-bar "$DOWNLOAD_URL"
printf '%s  %s\n' "$sha256" "$ARCHIVE" | sha256sum -c -

echo "Extracting source code..."
tar -xzf "$ARCHIVE"
cd "lua-${VERSION}"

echo "Compiling Lua ${VERSION}..."
make all test

rollback() {
    status=$?
    if [ "$status" -ne 0 ]; then
        echo "Install failed; restoring the previous Lua GitHub build when possible."
        sudo rm -rf "$STAGING_DIR"
        if [ -d "$BACKUP_DIR" ]; then
            sudo rm -rf "$RELEASE_DIR"
            sudo mv "$BACKUP_DIR" "$RELEASE_DIR"
            sudo ln -sfn "$RELEASE_DIR" "$CURRENT_LINK"
        fi
    fi
    exit "$status"
}
trap rollback EXIT

echo "Installing Lua ${VERSION} under ${INSTALL_ROOT}..."
sudo mkdir -p "${INSTALL_ROOT}/releases"
sudo rm -rf "$STAGING_DIR" "$BACKUP_DIR"
sudo make INSTALL_TOP="$STAGING_DIR" install

if [ -d "$RELEASE_DIR" ]; then
    sudo mv "$RELEASE_DIR" "$BACKUP_DIR"
fi

sudo mv "$STAGING_DIR" "$RELEASE_DIR"
sudo ln -sfn "$RELEASE_DIR" "$CURRENT_LINK"
sudo ln -sfn "${CURRENT_LINK}/bin/lua" /usr/local/bin/lua-github
sudo ln -sfn "${CURRENT_LINK}/bin/luac" /usr/local/bin/luac-github

lua-github -v
command -v lua-github
sudo rm -rf "$BACKUP_DIR"
trap - EXIT

echo "Lua GitHub install complete."
SCRIPT_EOF

Make the Lua Helper Executable

Set executable permissions with the chmod command in Linux and confirm that your shell can find the helper:

sudo chmod 0755 /usr/local/bin/install-lua-github
command -v install-lua-github
/usr/local/bin/install-lua-github

Run the Lua GitHub Helper

Start the interactive installer as your regular user:

install-lua-github

The prompt lists stable GitHub releases, selects the newest release when you press Enter, and lets you choose an older displayed release by number. The sample output shows Lua 5.5.0; future runs may show a newer tag when Lua publishes another stable release.

Checking Lua releases from GitHub...
GitHub API unavailable; falling back to the public GitHub Releases page.
Current Lua GitHub install: missing
Latest GitHub release:     v5.5.0

Available stable releases:
 1) v5.5.0
 2) v5.4.8
 3) v5.4.7
Select a release number, press Enter for v5.5.0, or type q to quit:
Selected Lua release: v5.5.0
Resolving SHA-256 checksum from lua.org...
Downloading lua-5.5.0.tar.gz...
lua-5.5.0.tar.gz: OK
Extracting source code...
Compiling Lua 5.5.0...
Installing Lua 5.5.0 under /usr/local/lua-github...
Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio
/usr/local/bin/lua-github
Lua GitHub install complete.

The GitHub API fallback line is normal when GitHub rate limits unauthenticated API requests or when jq is not installed. The helper then reads the public release page and continues with the same version-selection flow.

Verify Source-Built Lua

Check the source-built interpreter, compiler, command path, and resolved symlink target:

lua-github -v
luac-github -v
command -v lua-github
readlink -f /usr/local/bin/lua-github
Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio
Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio
/usr/local/bin/lua-github
/usr/local/lua-github/releases/5.5.0/bin/lua

Install a Pinned Lua Release Later

Rerun the helper when you want to move between upstream releases. Press Enter for the newest stable release or type the number beside a listed tag, such as 2 for v5.4.8 when that tag appears in the menu:

install-lua-github

When the selected version is already active, the helper exits without rebuilding:

Current Lua GitHub install: 5.5.0
Latest GitHub release:     v5.5.0
Lua 5.5.0 is already installed through /usr/local/lua-github/current.

Install Lua Modules and LuaRocks on Ubuntu

Lua modules may come from Ubuntu packages or from LuaRocks. Prefer Ubuntu packages for system-managed software, and use LuaRocks for project-specific modules or modules that Ubuntu does not package.

Module SourceUse CaseMaintenance Behavior
Ubuntu lua-* packagesSystem packages and dependencies maintained through APTUpdated with normal Ubuntu package upgrades
LuaRocksProject modules, development dependencies, and modules not available as Ubuntu packagesManaged with luarocks commands

Install LuaRocks with APT

Install LuaRocks from Ubuntu repositories:

sudo apt install luarocks

Confirm the installed LuaRocks command:

luarocks --version | head -n1
/usr/bin/luarocks 3.8.0

Test Lua on Ubuntu

Use a one-line test to confirm the interpreter branch that a command runs. On Ubuntu 26.04, test the Lua 5.5 package with:

lua5.5 -e 'print("Hello from " .. _VERSION)'
Hello from Lua 5.5

On Ubuntu 24.04 and 22.04, use the Lua 5.4 command instead:

lua5.4 -e 'print("Hello from " .. _VERSION)'
Hello from Lua 5.4

Test the GitHub source-built interpreter with its separate command name:

lua-github -e 'print("Hello from " .. _VERSION)'
Hello from Lua 5.5

Create and run a small Lua script with the interpreter available from your chosen method:

cat > hello.lua <<'EOF'
local message = "Lua script works"
print(message)
EOF

if command -v lua-github >/dev/null 2>&1; then
    lua-github hello.lua
elif command -v lua5.5 >/dev/null 2>&1; then
    lua5.5 hello.lua
else
    lua5.4 hello.lua
fi
rm hello.lua
Lua script works

Update Lua on Ubuntu

APT-installed Lua packages update through normal package upgrades. On Ubuntu 26.04, update the Lua 5.5 branch and any optional module tools you installed with:

sudo apt update
sudo apt install --only-upgrade lua5.5 luarocks luajit

On Ubuntu 24.04 and 22.04, use the Lua 5.4 branch instead:

sudo apt update
sudo apt install --only-upgrade lua5.4 luarocks luajit

The --only-upgrade option prevents APT from installing LuaRocks or LuaJIT if those optional packages are not already present.

Update a source-built Lua release by rerunning the helper and selecting the release you want:

install-lua-github

Avoid unattended source rebuilds for Lua. Run install-lua-github manually so checksum errors, compiler failures, or upstream changes are visible before the active symlink changes.

Troubleshoot Lua on Ubuntu

Fix Unable to Locate Lua Packages

If APT cannot locate a Lua package, verify both the package name and the repository component. Ubuntu 24.04 and 22.04 do not package lua5.5, so use lua5.4 or the GitHub source helper on those releases.

apt-cache policy lua5.5 lua5.4

If lua5.4 has no candidate, enable the required Ubuntu repository component, refresh APT, and retry the install.

Fix the Wrong Lua Version Running

Multiple Lua packages can register alternatives for the generic lua command. Inspect the active command and use versioned binaries in scripts when exact compatibility matters:

command -v lua
lua -v
update-alternatives --display lua-interpreter

For executable Lua scripts, choose the branch intentionally in the shebang:

#!/usr/bin/env lua5.4
print(_VERSION)

Fix Missing lua.h Header Errors

Build failures that mention lua.h usually mean the development header package is missing or the build is looking for a different Lua branch. Install the matching development package and verify the header path:

sudo apt install liblua5.4-dev
dpkg -S /usr/include/lua5.4/lua.h

For Ubuntu 26.04 builds targeting Lua 5.5, install liblua5.5-dev and check /usr/include/lua5.5/lua.h.

Fix GitHub API or Checksum Errors

The helper can continue without the GitHub API by parsing the public release page. If checksum discovery or verification fails, stop the install, remove the partial work directory for that version, and retry after confirming the release is listed on both GitHub and Lua.org:

rm -rf "$HOME/lua-github-source-build/lua-5.5.0" "$HOME/lua-github-source-build/lua-5.5.0.tar.gz"
install-lua-github

If you selected a different release, replace 5.5.0 with the selected version in both cleanup paths.

Remove Lua from Ubuntu

Review installed packages before removing Lua. Other applications may depend on a Lua runtime, LuaJIT, LuaRocks, or development headers.

Remove APT Lua Packages

List installed Lua-related packages before choosing what to remove:

dpkg -l 'lua5.*' luajit luarocks 'liblua5.*-dev' | grep '^ii'

Remove only the packages you installed and no longer need. For a common Lua 5.4 setup, remove these packages:

sudo apt remove lua5.4 luarocks luajit

Remove Ubuntu 26.04 Lua 5.5 packages when they are installed:

sudo apt remove lua5.5 liblua5.5-dev

Remove compatibility branches and Lua 5.4 headers only when you are sure no local project still uses them:

sudo apt remove lua5.3 lua5.2 lua5.1 liblua5.4-dev

Review any orphaned dependencies before cleaning them up:

sudo apt autoremove --dry-run

Remove GitHub Source-Built Lua

This cleanup removes the managed GitHub Lua prefix and helper paths created by these steps. It does not remove Ubuntu APT packages such as lua5.4 or luarocks.

sudo rm -f /usr/local/bin/lua-github /usr/local/bin/luac-github /usr/local/bin/install-lua-github
sudo rm -rf /usr/local/lua-github
rm -rf "$HOME/lua-github-source-build"
hash -r
command -v lua-github || echo "lua-github removed"
lua-github removed

Remove User-Local LuaRocks Data

LuaRocks can store user-local modules under ~/.luarocks. Remove that directory only when you no longer need user-local rocks:

This command deletes all LuaRocks modules installed under the current user’s home directory. Leave the directory in place if any active project still uses those modules.

rm -rf "$HOME/.luarocks"

Conclusion

Lua is available on Ubuntu through versioned APT packages, while lua-github gives you a checksum-verified source build for current or pinned upstream releases without replacing Ubuntu package commands. For related development workflows, connect Lua scripts to local data with SQLite on Ubuntu, edit scripts with Neovim on Ubuntu, or test services inside Docker on Ubuntu.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: