最近在配置新电脑的lua环境,之前安装的步骤也忘的差不多了,这里重新记录下安装的步骤。
方法一:
通过homebrew 安装,homebrew的安装方式前面有写过 [https://www.cnblogs.com/xiaoqiangink/p/13354644.html]
brew install lua
brew install luarocks
通过luarocks安装luasocket luasocket lzmq
luarocks install luasocket
luarocks install lzmq
注意:homebrew 安装的都是最新的版本,我还没测试出来怎么选择版本更新,好像记得可以通过brew info xx之类,去看输出信息,找到源文件下载地址,再对应去更改其中的文件路径,没有测试出来方法,只好作罢。
方法二:
针对性的选择需要版本的压缩包安装,首先你要从官网上载lua 和luarocks的压缩包。
Lua:
curl -R -O http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar zxf lua-5.1.4.tar.gz
cd lua-5.1.4
make macosx test
make install
Luarocks:
请在 http://luarocks.org/releases/ 或者是http://luarocks.github.io/luarocks/releases页面选择需要的软件包。可能要翻或者找个代理才可以打开。
tar -zxvf luarocks-3.2.1.tar.gz
cd luarocks-2.1.0
./configure --prefix=/usr/local/luarocks --with-lua-include=/usr/local/lua/src
(prefix是指定LuaRocks的安装包解压缩后文件路径, with-lua-include 安装的lua文件位置)
make
sudo make install
make bootstrap
接下来就可以用luarocks安装需要的库文件了,唯一的问题是路径问题,安装成功后进行require,发现报错,提示找不到source 文件
/usr/local/lib/xx ,/usr/local/share/xx
看了下configure文件,不知道哪里可以修改luarocks的路径配置, 不过有发现:luarocks安装后的东西都放在:/luarocks-3.2.1/lua_modules 这个文件夹下,把所需要库的lib和share各自copy到/usr/local/lib/lua/5.1/ 和/usr/local/share/lua/5.1/即可。
方法一和方法二没什么差别,主要区别是为了选择不同版本的安装,个人感觉最好是通过brew 来做。因为brew安装的source包都集中在/usr/local/Cellar,比较好管理,但是没仔细研究过用brew 安装指定版本,所以暂时放弃选择安装包安装。
4.重点
网上通常会说执行 ./configure --prefix=/usr/local/luarocks-2.2.2 --with-lua=/usr/local/lua-5.3.0,但是这样的路径不一定和你Mac下lua环境相同,
这里的两个路径需要视情况而定选择对应的目录,可以在/usr/local里找一下lua.h的文件路径我这里是/usr/local/include,–prefix可以用默认的,所以我这里需要配置的是
$ ./configure --with-lua=/usr/local --with-lua-include=/usr/local/include
然后
$ make build
$ make install
Luarocks 安装艰难过程
1.最好新建一个你自己的目录,然后把lua + Luarocks 都安装在这个文件夹下面,方便以后维护
2.安装lua环境
$ wget http://www.lua.org/ftp/lua-5.3.0.tar.gz
$ tar zxvf lua-5.3.0.tar.gz
$ cd lua-5.3.0
$ vi Makefile
INSTALL_TOP= /usr/local/lua-5.3.0 --指定安装的目录
$ make linux
$ make install
3. 安装luarocks 环境
$ wget http://keplerproject.github.io/luarocks/releases/luarocks-2.2.2.tar.gz
$ tar -xzvf luarocks-2.2.2.tar.gz
$ cd luarocks-2.2.2
$ ./configure --prefix=/usr/local/luarocks-2.2.2 --with-lua=/usr/local/lua-5.3.0 (luarocks-2.2.2 所在目录,lua-5.3.0配置的安装目录INSTALL_TOP= /usr/local/lua-5.3.0 --指定安装的目录)
$ make build
$ make install
4.重点来了,我执行 ./configure --prefix=/usr/local/luarocks-2.2.2 --with-lua=/usr/local/lua-5.3.0 一直报下面的错误
报错信息:[root@test-l27-15-165 luarocks-2.2.2]# ./configure --prefix=/usr/fxj/luarocks-2.2.2 --with-lua=/usr/local/include/
Checking Lua interpreter... lua not found (looked in /usr/local/include//bin)
You may want to use the flag --with-lua or --with-lua-bin. See --help.
configure failed.
那么这个路径具体该怎么设置呢?
luarocks-2.2.2这会是这个解压包所在的路径,/usr/local/lua-5.3.0这个是INSTALL_TOP= /usr/local/lua-5.3.0
[root@test-l27-15-165 luarocks-2.2.2]# ./configure --prefix=/usr/fxj/luarocks-2.2.2 --with-lua=/usr/local/lua-5.3.0
Lua interpreter found: /usr/local/lua-5.3.0/bin/lua...
Lua version detected: 5.3
Checking Lua includes... lua.h found in /usr/local/lua-5.3.0/include/lua.h
curl found at /usr/bin
md5sum found at /usr/bin
Configuring for system... Linux
Configuring for architecture... x86_64
Using unversioned rocks dir: /usr/fxj/luarocks-2.2.2/lib/luarocks/rocks
Writing configuration...
Installation prefix: /usr/fxj/luarocks-2.2.2
LuaRocks configuration directory: /usr/fxj/luarocks-2.2.2/etc/luarocks
Using Lua from: /usr/local/lua-5.3.0
Done configuring.
- Type 'make build' and 'make install':
to install to /usr/fxj/luarocks-2.2.2 as usual.
- Type 'make bootstrap':
to install LuaRocks in /usr/fxj/luarocks-2.2.2 as a rock.
蓝色为结果
提示找不到lua.h,默认情况下会从/usr下寻找
再次执行:
[root@test-l27-15-165 luarocks-2.2.2]# find / -name = lua.h
find: paths must precede expression: lua.h
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[root@test-l27-15-165 luarocks-2.2.2]# find / -name lua.h
/usr/fxj/lua-5.3.0/src/lua.h
/usr/local/include/lua.h
/usr/local/lua-5.3.0/include/lua.h
再次执行下面这个命令:
./configure --with-lua=/usr/local --with-lua-include=/usr/local/include
$ make build
$ make install
5.输入下面验证是否安装成功:
[root@test-l27-15-165 luarocks-2.2.2]# luarocks
LuaRocks 2.2.2, a module deployment system for Lua
NAME
/usr/local/bin/luarocks - LuaRocks main command-line interface
SYNOPSIS
/usr/local/bin/luarocks [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>