luarocks在macOS系統上的安裝


luarocks是基於lua開發的一個包管理工具,所以在安裝luarocks之前需要先安裝lua(見博客同目錄下“lua在MacOS系統上的安裝”)。具體的安裝步驟如下:

1.源碼安裝部署luarocks

其實除了源碼安裝,我們還有其他可以選擇的安裝方法,比如brew,apt-get,yum等,這里選擇源碼安裝:

$ wget http://luarocks.org/releases/luarocks-2.2.2.tar.gz
$ tar zxvf luarocks-2.2.2.tar.gz
$ cd luarocks-2.2.2
$ ./configure sudo make bootstrap
$ sudo luarocks install luasocket
$ lua
> require "socket"

注:上面的命令是官網的文檔里的,與百度到的博客不一致。經實際操作,官網上的可以完美安裝,現有博客上的不行。

輸出的結果如下:

zfydeMacBook-Pro:luarocks-2.2.2 zfy$ ./configure --help
Configure LuaRocks.

--help                      This help.
--prefix=DIR                Prefix where LuaRocks should be installed.
                            Default is /usr/local
--sysconfdir=DIR            Location where the config file should be installed.
                            Default is $PREFIX/etc/luarocks

Where to install files installed by rocks, to make the accessible to Lua and
your $PATH. Beware of clashes between files installed by LuaRocks and by your
system's package manager.

--rocks-tree=DIR            Root of the local tree of installed rocks.
                            Default is $PREFIX

--lua-version=VERSION       Use specific Lua version: 5.1, 5.2, or 5.3
                            Default is "5.1"
--lua-suffix=SUFFIX         Versioning suffix to use in Lua filenames.
                            Default is "" (lua...)
--with-lua=PREFIX           Use Lua from given prefix.
                            Default is auto-detected (the parent directory of $LUA_BINDIR).
--with-lua-bin=DIR          You can also specify Lua's bin dir.
                            Default is the directory of the auto-detected Lua interpreter,
                            or $LUA_DIR/bin if --with-lua is used.
--with-lua-include=DIR      You can also specify Lua's includes dir.
                            Default is $LUA_DIR/include
--with-lua-lib=DIR          You can also specify Lua's libraries dir.
                            Default is $LUA_DIR/lib
--with-downloader=TOOL      Which tool to use as a downloader.
                            Valid options are: curl, wget.
                            Default is to auto-detect.
--with-md5-checker=TOOL     Which tool to use as a downloader.
                            Valid options are: md5sum, openssl
                            Default is to auto-detect.
--versioned-rocks-dir       Use a versioned rocks dir, such as
                            $PREFIX/lib/luarocks/rocks-5.1/.
                            Default is to auto-detect the necessity.
--force-config              Use a single config location. Do not use the
                            $LUAROCKS_CONFIG variable or the user's home
                            directory. Useful to avoid conflicts when LuaRocks
                            is embedded within an application.

這里我們主要關注--prefix = DIR 和 --with-lua = PREFIX.

2.設置--prefix和--with-lua

--prefix 設置 Luarocks 安裝路徑,--with-lua 指定 Luarocks 依賴的 Lua 安裝路徑。

設置 prefix 會自動將 Luarocks 以及往后使用 Luarocks 安裝的 Lua 包,LuaC 包都安裝到 Luarocks 安裝路徑下的相應位置,否則相關的包文件散落在文件系統中,顯得雜亂不便於管理,如果所安裝的 Lua 模板包含 bin 文件,則會自動安裝到此目錄下的 bin 路徑,與 Luarocks 可執行文件同一路徑,更便於管理、使用。

 
         

 ./configure --prefix=/usr/local/luarocks-2.2.2 --with-lua=/Users/zfy/Downloads/lua-5.3.3//我電腦上luarocks和lua的相應版本

//--prefix和--with-lua這兩個變量的值取決於你電腦上luarocks和lua的位置,一般來說luarocks的位置是固定的/usr/local/luarocks-2.2.2,但是lua在安裝的時候路徑各不相同,比如說我的在/Users/zfy/Downloads下。所以請務必先確定上述兩者的位置,不要一味照搬。

make build make install

3.運行

直接在命令行運行luarocks即可。

 

關於luarocks的用法可查看github上的說明文檔,時間有限,本文暫時不翻譯了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM