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上的说明文档,时间有限,本文暂时不翻译了。