linux下lua開發環境安裝

來源:互聯網
上載者:User

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

 

wget http://www.lua.org/ftp/lua-5.1.0.tar.gztar -zxvf lua-5.1.0.tar.gzmake linux testmake install

 

lua有一個模組管理工具luarocks,類似於yum,我們可以使用luarocks來安裝相關模組。

1.安裝

 

wget http://luarocks.org/releases/luarocks-2.2.1.tar.gztar zxpf luarocks-2.2.1.tar.gzcd luarocks-2.2.1./configure
會出現以下提示:

 

 

Lua interpreter found: /usr/bin/lua...Lua version detected: 5.1lua found in $PATH: /usr/binChecking 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的目錄

 

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

再重新編譯安裝:

 

./configure --with-lua=/usr/local --with-lua-include=/usr/local/includemake bootstrap
我們就將luarocks安裝到/usr/local下了,加入以下環境變數,就可以直接使用了:

 

export PATH=/usr/local/bin:$PATH

lua可用模組列別,可以在此查看http://luarocks.org/repositories/rocks/,我們通過以下即可直接安裝:

 

[root@usvr-126 local]# luarocks install luafilesystemInstalling 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' modegcc -O2 -fPIC -I/usr/local/include -c src/lfs.c -o src/lfs.ogcc -shared -o lfs.so -L/usr/local/lib src/lfs.oUpdating manifest for /usr/local/lib/luarocks/rocksluafilesystem 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的設定檔中引用:

 

lua_package_path ‘/usr/local/nginx/lua/?.lua;;’lua_package_cpath ‘/usr/local/nginx/lua/lib/?.?;;’;#其中”;;”代表原先尋找範圍。
註:路徑自己定義,也可定義成預設路徑。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.