Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua cannot find installed luarocks on Ubuntu

I install luarocks:

$ sudo apt-get install luarocks

I install lua-cjson by luarocks:

$sudo luarocks install lua-cjson

show packages:

$luarocks list

Installed rocks:
----------------
lua-cjson
   2.1.0-1 (installed) - /usr/local/lib/luarocks/rocks

So, I see package:

$luarocks show lua-cjson

License:    MIT
Homepage:   http://www.kyne.com.au/~mark/software/lua-cjson.php
Installed in:   /usr/local
. . . 
Modules:
    cjson
    lua2json
    json2lua
    cjson.util


    lua-cjson
          2.1.0-1 (installed) - /usr/local/lib/luarocks/rocks

But, Lua can't see the module:

$lua
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> require "cjson"
stdin:1: module 'cjson' not found:
....


$locate cjson.so
 /usr/local/lib/lua/5.1/cjson.so

What it is the error??

like image 595
Alexandre Kalendarev Avatar asked Sep 29 '16 02:09

Alexandre Kalendarev


People also ask

Does Lua have a package manager?

LuaRocks is a package manager for the Lua programming language that provides a standard format for distributing Lua modules (in a self-contained format called a "rock"), a tool designed to easily manage the installation of rocks, and a server for distributing them.


1 Answers

The problem seems to be that luarocks by default installs things for Lua 5.1 (this is the behavior if you installed it using apt-get). If you don't mind using Lua 5.1, you can just use that instead (by typing lua5.1), and require "cjson" should work fine.

If you really want cjson for Lua 5.2, it's a bit more complicated. First, you need to make sure that you have the development files for Lua 5.2. Try

sudo apt-get install liblua5.2-dev

Then download the latest version of the source for luarocks here. Extract, and cd to the directory in a terminal.

Then do the following commands (from this post)

./configure --lua-version=5.2 --versioned-rocks-dir
make build
sudo make install

This will install a version of luarocks which works with Lua 5.2. You can then install cjson using

sudo luarocks-5.2 install lua-cjson

You should then be able to use cjson in Lua 5.2.

like image 65
fakedad Avatar answered Nov 02 '22 07:11

fakedad