Skip to content

Instantly share code, notes, and snippets.

@fferri
Created September 12, 2025 11:39
Show Gist options
  • Save fferri/8a9b457d4289393a7bc8e0ce4e7904e2 to your computer and use it in GitHub Desktop.
Save fferri/8a9b457d4289393a7bc8e0ce4e7904e2 to your computer and use it in GitHub Desktop.
Integration of luarocks with macOS apps

Integration of luarocks with macOS apps

Apps embedding lua won't find your luarocks installation out-of-the box.

In a terminal, you have to run:

eval $(luarocks path --lua-version 5.4 --bin)

which sets LUA_PATH and LUA_CPATH environment variables, but it applies only for apps launched from within that shell session.

To have those environment variables effective for all applications launched from macOS (Finder, Launch Control, etc) you have to use launchd:

#!/bin/sh

eval $(luarocks path --lua-version 5.4 --bin)
launchctl setenv LUA_PATH "$LUA_PATH"
launchctl setenv LUA_CPATH "$LUA_CPATH"

save the above into a script and run it.

You can also have it run automatically at login, by creating a LaunchAgents file e.g. ~/Library/LaunchAgents/org.luarocks.setenv.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.luarocks.setenv</string>

    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>/path/to/the/above/script.sh</string>
    </array>

    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

replace /path/to/the/above/script.sh with the actual path of the previous script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment