/[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.8 - (show annotations) (download) (as text)
Mon Aug 30 17:44:00 2004 UTC (10 years ago) by neysx
Branch: MAIN
Changes since 1.7: +9 -8 lines
File MIME type: application/xml
#62186: Fixed language mistakes all over the place thanks to John Richards

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

  ViewVC Help
Powered by ViewVC 1.1.20