1、自1.11.2.2开始,OpenResty版本已经包含并默认安装opm。所以通常你不需要自己安装opm。

2、我们在这里只需要做一个软连接就可以了

cd /usr/local/openresty/bin
sudo ln -s `pwd`/opm /usr/local/bin/opm

3、搜索指定软件包名称

www@TinywanAliYun:~$ opm search session
bungle/lua-resty-session                          Session Library for OpenResty - Flexible and Secure

4、搜索具有多个模式“lru”和“cache”的软件包名称和摘要。

www@TinywanAliYun:~$ opm search lru cache
openresty/lua-resty-lrucache                      Lua-land LRU Cache based on LuaJIT FFI

5、在一些作者的名字下安装名为lua-resty-logger-socket的软件包

www@TinywanAliYun:~$ opm get p0pr0ck5/lua-resty-logger-socket* Fetching p0pr0ck5/lua-resty-logger-socket  
  Downloading https://opm.openresty.org/api/pkg/tarball/p0pr0ck5/lua-resty-logger-socket-0.03.opm.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7423  100  7423    0     0  23691      0 --:--:-- --:--:-- --:--:-- 23715
Package p0pr0ck5/lua-resty-logger-socket 0.03 installed successfully under /usr/local/openresty/site/ .

 结果在  /usr/local/openresty/lualib/resty  目录下没有这个文件下载下来

结果该文件默认下载到以下目录了

/usr/local/openresty/site/lualib/resty

 编写代码测试

local uuid = require 'resty.jit-uuid'
ngx.say(uuid())

问题来了,项目中直接应用,报错,提示找不到该文件

[C]: in function 'require'
	 in function /status"
[error] 7626#7626: init_worker_by_lua error: init_worker_by_lua:2: module 'resty.jit-uuid' not found:
	no field package.preload['resty.jit-uuid']
	no file '/usr/local/openresty/lualib/resty/jit-uuid.lua'
	no file '/usr/local/openresty/nginx/conf/waf/resty/jit-uuid.lua'
	no file '/usr/local/openresty/lualib/resty/jit-uuid.so'
	no file '/opt/verynginx/verynginx/lua_script/resty/jit-uuid.so'
	no file '/usr/local/openresty/site/lualib/resty/jit-uuid.so'
	no file '/usr/local/openresty/lualib/resty/jit-uuid.so'

如果复制到该目录下,则是可以正常访问的

/usr/local/openresty/lualib/resty  

要想安装到以上目录 

则在下载的时候指定安装目录就可以了

opm --install-dir=/usr/local/openresty get thibaultcha/lua-resty-jit-uuid  

通过上面这种安装方式,直接在项目中就可以使用

参考

1、OpenResty 大跃进! opm 包管理尝鲜