When using Lua-based plugins for Neovim, you may need to install some packages
with luarocks. To use these packages, the environment variables LUA_PATH
and
LUA_CPATH
needs to contain the luarocks directories. Problem is, Neovim uses
LuaJIT which is a Lua 5.1 implementation; however, you may already have your
environment setup for a different Lua version, for example the current last
version 5.4. To resolve this problem, this gist patches the Lua paths in the
startup configuration instead of relying on the environment variables as is
default in Neovim.
Last active
January 6, 2023 20:32
-
-
Save Lattay/84af7aa1fad7eab055d3636220638a3f to your computer and use it in GitHub Desktop.
Configure luarocks for Neovim at startup (Linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ~/.config/nvim/init.lua | |
-- Do your usual general config stuff | |
require "setup_rocks" | |
-- Load your plugins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ~/.config/nvim/lua/setup_rocks.lua | |
local home = os.getenv("HOME") | |
if home == nil then | |
return | |
end | |
local path = table.concat({ | |
'/usr/share/lua/5.1/?.lua', | |
'/usr/share/lua/5.1/?/init.lua', | |
'/usr/lib/lua/5.1/?.lua', | |
'/usr/lib/lua/5.1/?/init.lua', | |
'./?.lua', | |
'./?/init.lua', | |
'~/.luarocks/share/lua/5.1/?.lua', | |
'~/.luarocks/share/lua/5.1/?/init.lua' | |
}, ";") | |
local cpath = table.concat({ | |
'/usr/lib/lua/5.1/?.so', | |
'/usr/lib/lua/5.1/loadall.so', | |
'./?.so', | |
'~/.luarocks/lib/lua/5.1/?.so' | |
}, ";") | |
package.path = path:gsub("~", home) | |
package.cpath = cpath:gsub("~", home) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment