/[gentoo]/xml/htdocs/doc/en/handbook/hb-working-variables.xml
Gentoo

Contents of /xml/htdocs/doc/en/handbook/hb-working-variables.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download) (as text)
Mon Mar 1 05:43:42 2004 UTC (10 years, 9 months ago) by swift
Branch: MAIN
Changes since 1.5: +1 -1 lines
File MIME type: application/xml
Move from draft - 2004.0 is released

1 <?xml version='1.0' encoding='UTF-8'?>
2 <!DOCTYPE sections SYSTEM "/dtd/book.dtd">
3
4 <!-- The content of this document is licensed under the CC-BY-SA license -->
5 <!-- See http://creativecommons.org/licenses/by-sa/1.0 -->
6
7 <!-- $Header: /home/cvsroot/gentoo/xml/htdocs/doc/en/handbook/draft/hb-working-variables.xml,v 1.1 2004/02/16 05:41:21 swift Exp $ -->
8
9 <sections>
10 <section>
11 <title>Environment Variables?</title>
12 <subsection>
13 <title>What they are</title>
14 <body>
15
16 <p>
17 An environment variable is a named object that contains information used by one
18 or more applications. Many users (and especially those new to Linux) find this a
19 bit weird or unmanageable. This is however wrong: by using environment variables
20 one can easily change a configuration setting for one or more applications.
21 </p>
22
23 </body>
24 </subsection>
25 <subsection>
26 <title>Important Examples</title>
27 <body>
28
29 <p>
30 The following table lists a number of variables used by a Linux system and
31 describes their use. Example values are presented after the table.
32 </p>
33
34 <table>
35 <tr>
36 <th>Variable</th>
37 <th>Description</th>
38 </tr>
39 <tr>
40 <ti>PATH</ti>
41 <ti>
42 This variable contains a colon-separated list of directories in which your
43 system looks for executable files. If you enter a name of an executable
44 (such as <c>ls</c>, <c>rc-update</c> or <c>emerge</c>) but this executable
45 is not located in a listed directory, your system will not execute it
46 (unless you enter the full path as command, such as <c>/bin/ls</c>).
47 </ti>
48 </tr>
49 <tr>
50 <ti>ROOTPATH</ti>
51 <ti>
52 This variable has the same function as <c>PATH</c>, but this one only lists
53 the directories that should be checked when the root-user enters a command.
54 </ti>
55 </tr>
56 <tr>
57 <ti>LDPATH</ti>
58 <ti>
59 This variable contains a colon-separated list of directories in which the
60 dynamical linker searches through to find a library.
61 </ti>
62 </tr>
63 <tr>
64 <ti>MANPATH</ti>
65 <ti>
66 This variable contains a colon-separated list of directories in which the
67 <c>man</c> command searches for the man pages.
68 </ti>
69 </tr>
70 <tr>
71 <ti>INFODIR</ti>
72 <ti>
73 This variable contains a colon-separated list of directories in which the
74 <c>info</c> command searches for the info pages.
75 </ti>
76 </tr>
77 <tr>
78 <ti>PAGER</ti>
79 <ti>
80 This variable contains the path to the program used to list the contents of
81 files through (such as <c>less</c> or <c>more</c>).
82 </ti>
83 </tr>
84 <tr>
85 <ti>EDITOR</ti>
86 <ti>
87 This variable contains the path to the program used to change the contents
88 of files with (such as <c>nano</c> or <c>vi</c>).
89 </ti>
90 </tr>
91 <tr>
92 <ti>KDEDIRS</ti>
93 <ti>
94 This variable contains a colon-separated list of directories which contain
95 KDE-specific material.
96 </ti>
97 </tr>
98 <tr>
99 <ti>CLASSPATH</ti>
100 <ti>
101 This variable contains a colon-separated list of directories which contain
102 Java classes.
103 </ti>
104 </tr>
105 <tr>
106 <ti>CONFIG_PROTECT</ti>
107 <ti>
108 This variable contains a <e>space</e>-delimited list of directories which
109 should be protected by Portage during updates.
110 </ti>
111 </tr>
112 <tr>
113 <ti>CONFIG_PROTECT_MASK</ti>
114 <ti>
115 This variable contains a <e>space</e>-delimited list of directories which
116 should not be protected by Portage during updates.
117 </ti>
118 </tr>
119 </table>
120
121 <p>
122 Below you will find an example definition of all these variables:
123 </p>
124
125 <pre caption="Example definitions">
126 PATH="/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/games/bin"
127 ROOTPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
128 LDPATH="/lib:/usr/lib:/usr/local/lib:/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
129 MANPATH="/usr/share/man:/usr/local/share/man"
130 INFODIR="/usr/share/info:/usr/local/share/info"
131 PAGER="/usr/bin/less"
132 EDITOR="/usr/bin/vim"
133 KDEDIRS="/usr"
134 CLASSPATH="/opt/blackdown-jre-1.4.1/lib/rt.jar:."
135 CONFIG_PROTECT="/usr/X11R6/lib/X11/xkb /opt/tomcat/conf \
136 /usr/kde/3.1/share/config /usr/share/texmf/tex/generic/config/ \
137 /usr/share/texmf/tex/platex/config/ /usr/share/config"
138 CONFIG_PROTECT_MASK="/etc/gconf
139 </pre>
140
141 </body>
142 </subsection>
143 </section>
144 <section>
145 <title>Defining Variables Globally</title>
146 <subsection>
147 <title>The /etc/env.d Directory</title>
148 <body>
149
150 <p>
151 To centralise the definitions of these variables, Gentoo introduced the
152 <path>/etc/env.d</path> directory. Inside this directory you will find a number
153 of files, such as <path>00basic</path>, <path>05gcc</path>, etc. which contain
154 the variables needed by the application mentioned in their name.
155 </p>
156
157 <p>
158 For instance, when you installed <c>gcc</c>, a file called <path>05gcc</path>
159 was created by the ebuild which contains the definitions of the following
160 variables:
161 </p>
162
163 <pre caption="/etc/conf.d/05gcc">
164 PATH="/usr/i686-pc-linux-gnu/gcc-bin/3.2"
165 ROOTPATH="/usr/i686-pc-linux-gnu/gcc-bin/3.2"
166 MANPATH="/usr/share/gcc-data/i686-pc-linux-gnu/3.2/man"
167 INFOPATH="/usr/share/gcc-data/i686-pc-linux-gnu/3.2/info"
168 CC="gcc"
169 CXX="g++"
170 LDPATH="/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
171 </pre>
172
173 <p>
174 Other distributions tell you to change or add such environment variable
175 definitions in <path>/etc/profile</path> or other locations. Gentoo on the other
176 hand makes it easy for you (and for Portage) to maintain and manage the
177 environment variables without having to pay attention to the numerous files that
178 can contain environment variables.
179 </p>
180
181 <p>
182 For instance, when <c>gcc</c> is updated, the <path>/etc/env.d/05gcc</path> file
183 is updated too without requesting any user-interaction.
184 </p>
185
186 <p>
187 This doesn't only benefit Portage, but also you, as user. Occasionally you might
188 be asked to set a certain environment variable system-wide. As an example we
189 take the <c>http_proxy</c> variable. Instead of messing with
190 <path>/etc/profile</path>, you can now just create a file
191 (<path>/etc/env.d/99local</path>) and enter your definition(s) in it:
192 </p>
193
194 <pre caption="/etc/env.d/99local">
195 http_proxy="proxy.server.com:8080"
196 </pre>
197
198 <p>
199 By using the same file for all your variables, you have a quick overview on the
200 variables you have defined yourself.
201 </p>
202
203 </body>
204 </subsection>
205 <subsection>
206 <title>The env-update Script</title>
207 <body>
208
209 <p>
210 Several files in <path>/etc/env.d</path> define the <c>PATH</c> variable. This
211 is not wrong: when you run <c>env-update</c>, it will append the several
212 definitions before it updates the environment variables, thereby making it easy
213 for packages (or users) to add their own environment variable settings without
214 interfering with the already existing values.
215 </p>
216
217 <p>
218 The <c>env-update</c> script will append the values in the alphabetical order of
219 the <path>/etc/env.d</path> files. This is why many of the files in
220 <path>/etc/env.d</path> begin with a number.
221 </p>
222
223 <pre caption="Update order used by env-update">
224 00basic 99kde-env 99local
225 +-------------+----------------+-------------+
226 PATH="/bin:/usr/bin:/usr/kde/3.2/bin:/usr/local/bin"
227 </pre>
228
229 <p>
230 When you run <c>env-update</c>, the script will create all environment variables
231 and place them in <path>/etc/profile.env</path> (which is used by
232 <path>/etc/profile</path>). It will also extract the information from the
233 <c>LDPATH</c> variable and use that to create <path>/etc/ld.so.conf</path>.
234 After this, it will run <c>ldconfig</c> to recreate the
235 <path>/etc/ld.so.cache</path> file used by the dynamical linker.
236 </p>
237
238 <p>
239 If you want to notice the effect of <c>env-update</c> immediately after you run
240 it, execute the following command to update your environment. Users who have
241 installed Gentoo themselves will probably remember this from the installation
242 instructions:
243 </p>
244
245 <pre caption="Updating the environment">
246 # <i>env-update &amp;&amp; source /etc/profile</i>
247 </pre>
248
249 </body>
250 </subsection>
251 </section>
252 <section>
253 <title>Defining Variables Locally</title>
254 <subsection>
255 <title>User Specific</title>
256 <body>
257
258 <p>
259 You do not always want to define an environment variable globally. For instance,
260 you might want to add <path>/home/my_user/bin</path> to the <c>PATH</c> variable
261 but don't want all other users on your system to have that in their <c>PATH</c>
262 too. If you want to define an environment variable locally, you should use
263 <path>~/.bashrc</path> or <path>~/.bash_profile</path>:
264 </p>
265
266 <pre caption="Extending PATH for local usage in ~/.bashrc">
267 PATH="${PATH}:/home/my_user/bin"
268 </pre>
269
270 <p>
271 When you relogin, your <c>PATH</c> variable will be updated.
272 </p>
273
274 </body>
275 </subsection>
276 <subsection>
277 <title>Session Specific</title>
278 <body>
279
280 <p>
281 Sometimes even stricter definitions are requested. You might want to be able to
282 use binaries from a temporary directory you created without using the path to
283 the binaries themselves or editing <path>~/.bashrc</path> for those few moments
284 you need it.
285 </p>
286
287 <p>
288 In this case, you can just define the <c>PATH</c> variable in your current
289 session by using the <c>export</c> command. As long as you don't log out, the
290 <c>PATH</c> variable will be using the temporary settings.
291 </p>
292
293 <pre caption="Defining a session-specific environment variable">
294 # <i>export PATH="${PATH}:/home/my_user/tmp/usr/bin"</i>
295 </pre>
296
297 </body>
298 </subsection>
299 </section>
300 </sections>

  ViewVC Help
Powered by ViewVC 1.1.20