最近在配置新電腦的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>