1
votes

I installed luarocks on centos7, then I execute 'luarocks install luacheck', there is an error:

'Error: Your user does not have write permissions in /usr/local/lib/luarocks/rocks
-- you may want to run as a privileged user or use your local tree with --local.'

So, I execute 'sudo luarocks install luacheck', but there is also an error:

'sudo luarocks command not found'.

I confirm that luarocks has installed correctly, bucause when I execte 'luarocks --version' shows:

/usr/bin/luarocks 2.4.2

2
This isn't so much a lua question as a Linux one :-) In any case, try it with a full path. As your normal user, do a 'which luarocks' to get the full path, then a 'sudo /path/to/luarocks' (without any options) just to see if something else is up. Rarely you may get a library error hiding behind the "command not found," but usually this is just a PATH variable problem (i.e. the one for your user != root's). - BJ Black

2 Answers

2
votes

As luarocks isn't installed using the native package manager its installed to /usr/local/bin. This isn't in the PATH variable available in the sudo context - you can see (and edit) the configured paths in the secure_path property in the sudoers file.

Workaround that I use it to add a symbolic link to a path included in the secure_path property: sudo ln -s /usr/local/bin/luarocks /usr/bin/luarocks

1
votes

You can either use

sudo /usr/bin/luarocks install luacheck

to install luacheck system-wide

or

luarocks --local install luacheck

to install to your user only. To use the second option, you also need to run

eval $(luarocks path --bin)

to make sure that the Lua paths are updated in your shell. To make these Lua paths permanent, you can add the above line to your shell config file (~/.bash_profile or similar).