生活随笔
收集整理的這篇文章主要介紹了
linux下lua开发环境安装
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我前面我們介紹了nginx+lua環境的搭建,在此我們再來了解下lua開發環境的安裝。
目前lua版本已經更新到lua5.3,但是我們在此安裝lua5.1,因為5.1運行了好多年,有好多模塊都是基于此版本的,例如lua_gd。
安裝:
1.先安裝lua的相關依賴
yum install readline-dev readline-devel
2.安裝lua5.1
[html] view plain
copy
wget?http://www.lua.org/ftp/lua-5.1.0.tar.gz??tar?-zxvf?lua-5.1.0.tar.gz?
make?linux?test??make?install??
lua有一個模塊管理工具luarocks,類似于yum,我們可以使用luarocks來安裝相關模塊。
1.安裝
[html] view plain
copy wget?http://luarocks.org/releases/luarocks-2.2.1.tar.gz??tar?zxpf?luarocks-2.2.1.tar.gz??cd?luarocks-2.2.1??./configure??
會出現以下提示:
[html] view plain
copy
Lua?interpreter?found:?/usr/bin/lua...?
Lua?version?detected:?5.1??lua?found?in?$PATH:?/usr/bin??Checking?Lua?includes...?lua.h?not?found?(looked?in?/usr/include,?/usr/include/lua/5.1,?/usr/include/lua5.1)??You?may?want?to?use?the?flag?--with-lua?or?--with-lua-include.?See?--help.????configure?failed.??
提示找不到lua.h,默認情況下會從/usr下尋找,因為我們需要指定lua.h的目錄
[html] view plain
copy find?/?-name?lua.h??/usr/local/luajit/include/luajit-2.0/lua.h??/usr/local/src/lua/lua-5.1.5/src/lua.h??/usr/local/src/lua/LuaJIT-2.0.4/src/lua.h??/usr/local/include/luajit-2.0/lua.h??/usr/local/include/lua.h??
再重新編譯安裝:
[html] view plain
copy
./configure?--with-lua=/usr/local?--with-lua-include=/usr/local/include??make?bootstrap?
我們就將luarocks安裝到/usr/local下了,加入以下環境變量,就可以直接使用了:
export PATH=/usr/local/bin:$PATH
lua可用模塊列別,可以在此查看http://luarocks.org/repositories/rocks/,我們通過以下即可直接安裝:
[html] view plain
copy [root@usvr-126?local]#?luarocks?install?luafilesystem??Installing?https://rocks.moonscript.org/luafilesystem-1.6.3-1.src.rock...??Using?https://rocks.moonscript.org/luafilesystem-1.6.3-1.src.rock...?switching?to?'build'?mode??gcc?-O2?-fPIC?-I/usr/local/include?-c?src/lfs.c?-o?src/lfs.o??gcc?-shared?-o?lfs.so?-L/usr/local/lib?src/lfs.o??Updating?manifest?for?/usr/local/lib/luarocks/rocks??luafilesystem?1.6.3-1?is?now?built?and?installed?in?/usr/local?(license:?MIT/X11)??
安裝完成后,會在/usr/local/lib/lua/5.1/下生成一個lfs.so的文件,我們只需要將此文件拷貝到nginx中自定義的LUA_PATH中,就可以引用該庫,調用其中的函數。
例如在nginx的配置文件中引用:
[html] view plain
copy lua_package_path?‘/usr/local/nginx/lua/?.lua;;’??lua_package_cpath?‘/usr/local/nginx/lua/lib/?.?;;’;??#其中”;;”代表原先查找范圍。??
注:路徑自己定義,也可定義成默認路徑。
來源:http://blog.csdn.net/yanggd1987/article/details/46681687
總結
以上是生活随笔為你收集整理的linux下lua开发环境安装的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。