aboutsummaryrefslogtreecommitdiff
path: root/docs/using_luarocks.md
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2025-01-05 21:40:39 -0300
committerHisham Muhammad <hisham@gobolinux.org>2025-02-21 11:22:43 -0300
commit7e86fa86b4d08fd6118d6eab46d92b29ffea791e (patch)
tree10fdd12beed4b0eca408533ad11d1f52d7d62e10 /docs/using_luarocks.md
parent1ada2ea4bbd94ac0c58e3e2cc918194140090a75 (diff)
downloadluarocks-7e86fa86b4d08fd6118d6eab46d92b29ffea791e.tar.gz
luarocks-7e86fa86b4d08fd6118d6eab46d92b29ffea791e.tar.bz2
luarocks-7e86fa86b4d08fd6118d6eab46d92b29ffea791e.zip
docs: import Wiki docs into the main repo
Diffstat (limited to 'docs/using_luarocks.md')
-rw-r--r--docs/using_luarocks.md198
1 files changed, 198 insertions, 0 deletions
diff --git a/docs/using_luarocks.md b/docs/using_luarocks.md
new file mode 100644
index 00000000..c65ef432
--- /dev/null
+++ b/docs/using_luarocks.md
@@ -0,0 +1,198 @@
1# Using LuaRocks
2
3So, you have followed the installation instructions (either on
4[Unix](installation_instructions_for_unix.md) or
5[Windows](installation_instructions_for_windows.md)) and now you have LuaRocks
6installed on your machine. Now you probably want to install some rocks
7(packages containing Lua modules) and use them in your Lua code.
8
9For LuaRocks to function properly, we have a quick checklist to go through
10first:
11
12# Command-line tools (and the system path)
13
14LuaRocks installs some command-line tools which are your interface for
15managing your rocks: [luarocks](luarocks.md) and
16[luarocks-admin](luarocks_admin.md). Make sure the directory where they are
17located is in your PATH -- the exact location depends on the flags you gave
18when installing LuaRocks.
19
20Run [luarocks](luarocks.md) to see the available commands:
21
22```
23luarocks
24```
25
26You can get help on any command by using the [luarocks help](luarocks_help.md) command:
27
28```
29luarocks help install
30```
31
32Installing packages is done by typing commands such as:
33
34```
35luarocks install dkjson
36```
37
38# Rocks trees and the Lua libraries path
39
40When you install rocks using the `luarocks install`, you get new modules
41available for loading via `require()` from Lua. For example, after we install
42the dkjson rock, type `luarocks show dkjson` to show the module installed by
43the rock:
44
45```
46luarocks show dkjson
47```
48
49This should output something like this:
50
51```
52dkjson 2.5-2 - David Kolf's JSON module for Lua
53
54dkjson is a module for encoding and decoding JSON data. It supports UTF-8.
55
56JSON (JavaScript Object Notation) is a format for serializing data based on the
57syntax for JavaScript data structures.
58
59dkjson is written in Lua without any dependencies, but when LPeg is available
60dkjson uses it to speed up decoding.
61
62License: MIT/X11
63Homepage: http://dkolf.de/src/dkjson-lua.fsl/
64Installed in: /usr/local
65
66Modules:
67 dkjson (/usr/local/share/lua/5.3/dkjson.lua)
68```
69
70It presents a short description of the rock, its license, and the list of
71modules it provides (in this case, only one, `dkjson`). Note that "Installed
72in:" shows the directory tree where the rock was installed. This is the "rocks
73tree" in use.
74
75Most LuaRocks installations will feature two rocks trees:
76
77* "system" [rock tree](rocks_repositories.md) (used by default)
78* "user" [rock tree](rocks_repositories.md)
79
80To be able to use the module, we need to make sure that Lua can find that
81dkjson.lua file when we run `require("dkjson")`. You can check your Lua paths
82from the Lua environment, using
83
84```
85print(package.path)
86print(package.cpath)
87```
88
89These variables can be pre-configured from outside Lua, using the LUA_PATH and
90LUA_CPATH environment variables.
91
92If you installed both Lua and LuaRocks in their default directories
93(/usr/local on Linux and Mac OSX), then the "system" tree is /usr/local and it
94will work by default. However, the "user" tree (for installing rocks without
95admin privileges) is not detected by Lua by default. For that we'll need to
96configure these environment variables.
97
98LuaRocks offers a semi-automated way to do this. If you type the following
99command:
100
101```
102luarocks path --bin
103```
104
105...it will print commands suitable for your platform for setting up your
106environment. On typical Unix terminal environments, you can type this:
107
108```
109eval "$(luarocks path --bin)"
110```
111
112and it apply the changes, temporarily, to your shell. To have these variables
113set permanently, you have to configure the environment variables to your shell
114configuration (for example, by adding the above line to your `.bashrc` file if
115your shell is Bash).
116
117# Multiple versions using the LuaRocks package loader
118
119If you want to make use of LuaRocks' support for multiple installed versions
120of modules, you need to load a custom package loader: luarocks.loader.
121
122You should be able to launch the Lua interpreter with the LuaRocks-enabled
123loader by typing:
124
125```
126lua -lluarocks.loader
127```
128
129Alternatively, you can load the LuaRocks module loader from Lua by issuing
130this command:
131
132```
133require "luarocks.loader"
134```
135
136If your system is correctly set up so that this command runs with no errors,
137subsequent calls to `require()` are LuaRocks-aware and the exact version of
138each module will be determined based on the dependency tree of previously
139loaded modules.
140
141# Scripts installed by rocks (and the scripts path)
142
143Besides modules, rocks can also install command-line scripts. The default
144location of this directory (unless you configured your local repository
145differently) is /usr/local/bin for system-wide installs and ~/.luarocks/bin
146for per-user installs on Unix and %APPDATA%/luarocks/bin on Windows -- make
147sure it is in your PATH as well.
148
149If you use the `--bin` argument in `luarocks path`, it will also print the
150appropriate PATH configuration:
151
152```
153luarocks path --bin
154```
155
156# Using in Unix systems with sudo
157
158When you use LuaRocks to install a package while you aren't root, the package
159will get installed in $HOME/.luarocks/ instead of the system-wide (by default,
160/usr/local/) and become only available for you. Moreover Lua doesn't know with
161its default setup that packages can be available in the current user's home.
162If you want to install a package available for all users, you should run it as
163superuser, typically using sudo.
164
165For example:
166
167```
168sudo luarocks install stdlib
169```
170
171After that, some files may not have correct permissions. For example, if
172/usr/local/share/lua/5.1/base.lua is only readable by root user, you should at
173least set them to readable for all users (chmod a+r or chmod 644).
174
175For example:
176
177```
178cd /usr/local/share/lua/5.1
179 sudo chmod a+r *
180```
181
182# Using a C compiler
183
184Because rocks are generally available in the repository as [source
185rocks](types_of_rocks.md) rather than binary rocks, it is best to have a C
186compiler available.
187
188On Windows, MinGW and Microsoft compilers are supported. The compiler should
189be in the system path, or explicitly configured in the LuaRocks config files.
190On Windows systems, one way of getting the compiler in the system path is to
191open the appropriate command prompt as configured by your compiler package
192(for example, the MSVC Command Prompt for Visual Studio).
193
194Note that for compiling binary rocks that have dependencies on other
195libraries, LuaRocks needs to be able to find [external
196dependencies](paths_and_external_dependencies.md).
197
198